rounding double in java

Credits: Gabri Le Cabri (from flickr)

Credits: Gabri Le Cabri (from flickr)

Rounding a double in java is very simple. If you have to round it to the nearest integer you could use the Math.round(double) method, but what about if you have to round it with a desired number of decimals?

Quite easy too. Using the BigDecimal.setScale(int,int) method you can choose how to round it. Following a quick example:

BigDecimal bd = new BigDecimal(123.45);
bd = bd.setScale(1,BigDecimal.ROUND_HALF_UP);
System.out.println(bd.doubleValue()); //should output 123.5

[Script-Fu] webify

Finally I entered also the Script-Fu world. For the photography school I’m attempting I had to deliver to my teacher about 350 photos. posting them i JPG full resolution would have been raving. So I though to my self, why don’t learn a bit of script-fu and do a script for Gimp that will convert a directory of JPG into others JPG of smalles size?

I know I could have searched for something already done but I wouldn’t have learned Script-Fu/scheme.

This is my first script. I surely have not followed conventions and surely it could have been done better. Maybe there will be a time when I will improve it. For now it’s it and it’s working for my tasks.

The script will take a single JPG or all JPGs in a Directory, resize it to a custom size (by long image side), default 800px, convert it to 72dpi and save it with a different name. Leave a color version or a quick conversion to grayscale. This last one is useful in order to have a look for an entire set if it looks better in color or B&W.

However here is the source code (pdf) to copy and paste into an scm file.