Casting int to double issue in JRockit -


i have bea weblogic 8.1 sp5 server running on jrockit instance following java version:

*java -version java version "1.4.2_10" java(tm) 2 runtime environment, standard edition (build 1.4.2_10-b03) bea jrockit(r) (build r26.3.0-32-58710-1.4.2_10-20060308-2022-linux-ia64, )*

i face issue when following code executed:

int debt = 27003; //amount in cents; system.out.println(((double) debt18 / 100)); //amount in euro

the printed result 270.03000000000003

i sure virtual machine error since observable on particular jrockit machine.

do happen face similar problem in past?

can please tell me less error-prone way pass wanted value double variable,preferably using standard java libraries?

i know pretty old have answer , maybe in future. used decimalformat object keep digits useful me. 1 decimal needed , correct, when error appeared ok me.

the code following:

string pattern = "##0.0#"; decimalformatsymbols separator = new decimalformatsymbols(); separator.setdecimalseparator('.'); decimalformat decimalformatter = new decimalformat(pattern, separator);  int debt = 27003; //amount in cents; system.out.println(decimalformatter.format(((double) debt18 / 100))); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -