Link to home
Start Free TrialLog in
Avatar of mooy
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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

try:


double d = 123.30;
DecimalFormat df = new DecimalFormat("0.0000");
String s = df.format(d);
long l = Long.parseLong(s);
Avatar of expertmb
expertmb

objects,
the above code gives number format exception.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yup!!! thts correct now :)
Avatar of mooy

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.