0

in xxxx.mxml (from flex) i have called the remote remote method (of java) the method return type is float in the xxxx.mxml's remote objects result handler i need get the float values as Numeric.....or String..i tried with string...i did Alert.show to see the value some times i get exact value for eg, 0.5 is the value returning from java methid but here it will show 0.50000454...so on..how get the exact value?

skolima
  • 31,963
  • 27
  • 115
  • 151
dpaksp
  • 727
  • 3
  • 12
  • 24

1 Answers1

0

It is because of the way floating point numbers are stored; basically they can't be stored precisely. A quick search in SO would reveal a lot of threads about this. Also read "What Every Computer Scientist Should Know About Floating-Point Arithmetic"

Thus the problem of getting the exact value boils down to what you define exact to be. Try rounding it to a given number of floating points at java end, convert the rounded number to a string (I'm not sure if this conversion would preserve the precision) and send that string.

Community
  • 1
  • 1
Amarghosh
  • 58,710
  • 11
  • 92
  • 121