开发者

Flash remoting and floating point values

开发者 https://www.devze.com 2023-01-05 08:32 出处:网络
in xxxx.mx开发者_开发问答ml (from flex) i have called the remote remote method (of java) the method return type is float

in xxxx.mx开发者_开发问答ml (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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消