Rounding to .0 or .5

I found this post on rounding via my RSS reader and started giggling since I myself wrestled with this problem a while back. I too started out with string operations etc. but ended up (after some discussion at the office) with a very easy solution.

The below code is in Java but should be easily convertable to JavaScript or any other language that allows you to round a number… The v-variable is a float holding the value we would like to round to .0 or .5:

int value = Math.round(v * 2);
float result = (float)value / 2;

It’s so simple it’s scary…

Update 3 May 2006: Updated the code based on feedback in comment.

Introduction to regular expressions in ten steps

If you have been following my blog for a while you know I’m a big fan of regular expressions. Previously I also showed you how to use Regular Expressions from LotusScript using the Microsoft VBScript component. What have been missing however was a simple “This is how to get going with regular expressions” tutorial but that has been solved. Take a look at Russ Olsen’s weblog and his two part series “Regular Expressions In Ten Steps”. Check it out using the links below.

I also recommend the Mastering Regular Expressions book from O’Reilly as a good guide into this exciting realm.

Optical keyboard? (includes pictures)

function previous() {
go(-1);
}
function next() {
go(1);
}
var filename_base = “./images/misc/optical_keyboard/optisk_keyboard-“;
var filename_ext = “.jpg”;
var start_counter = 1;
var max_counter = 5;
var counter = 1;

function go(step) {
// declarations
var prefix_number = “”;
var filename = “”;

// modify step
counter += step;
if (counter max_counter) {
counter = start_counter;
}

// calculate prefix
if (counter < 10) {
prefix_number = "0" + counter;
} else {
prefix_number = "" + counter;
}

// compose filename
filename = filename_base + prefix_number + filename_ext;

// get image division
var d = document.getElementById("slide_image");
d.innerHTML = "“;
}
function doStart() {
go(0);
}
window.onload = doStart;

How cool is this? At a client site today I saw an “optical” keyboard. The keyboard is projected from the black Bluetooth device onto the desk and works like any other keyboard once connected and configured. It works by tracking where your fingers meet the desk by using a laser grid. Nice – although very geeky!! 🙂

Previous | Next

(Use the above links to go through the pictures)

Previous | Next

(Use the above links to go through the pictures)