mooy
asked on
Java value conversion
hi everyone,
lets say i got a double value (123.30) i wanna convert it into a Long value (1233000) where the last 4 digits represents the decimal value. issit possible?
thnx
lets say i got a double value (123.30) i wanna convert it into a Long value (1233000) where the last 4 digits represents the decimal value. issit possible?
thnx
objects,
the above code gives number format exception.
the above code gives number format exception.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yup!!! thts correct now :)
ASKER
hmm.... this is the only way in getting round this?
I'm not sure but it looks as if you just want to move the decimal point 4 places to the right and then convert the resulting value to a long. Is this what you're looking for?
double doubleVal = 123.30;
long longVal = (long) (doubleVal * 10000);
longVal should now be 1233000
I hope that helps.
double doubleVal = 123.30;
long longVal = (long) (doubleVal * 10000);
longVal should now be 1233000
I hope that helps.
double d = 123.30;
DecimalFormat df = new DecimalFormat("0.0000");
String s = df.format(d);
long l = Long.parseLong(s);