go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
When you say 0.98 to Perl, it creates a "double" that has one of the closest possible values to 0.98. That isn't quite exactly 0.98, but it is pretty darn close. Close enough that if you asked Perl to convert this value back into a string, it would probably just give you "0.98". But you stored that value into a "single" in the database. Well, that got you one of the closest values to 0.98 that can fit into a "single". When you pull that back out of the database, Perl stores it into a "double" and later you ask it to convert it to a string. Well, Perl can tell that the number is close to 0.98 but not nearly as close as is possible when using a "double", so Perl doesn't just stop at "0.98". You see, when you convert 0.98 to a "double", you get something that is closer to 0.98 than 0.980000000000001 is. But in a "single", the closest you can get is either 0.979999542236328 or 0.980000019073486. So you need to grab only about the first 7 significant digits when converting a single to a string. Something like: $num= 0 + sprintf "%.6e", $num; - tye (but my friends call me "Tye")In reply to (tye)Re: Filthy Floats
by tye
|
|