Arc Forumnew | comments | leaders | submitlogin
How to prevent rounding on decimal numbers ?
1 point by thaddeus 5830 days ago | 4 comments
How can I prn the full number ?

    arc> (set x 34.123456789123456789123456789) 

    34.12345678912346

    arc> x

    34.12345678912346
Thanks. T.


4 points by cchooper 5830 days ago | link

You can't. MzScheme only stores floats to a limited precision.

  (is 34.12345678912346 34.123456789123456789123456789)
  => t
However, it will store rationals to any degree of precision.

  41152263004115226300411522630/11111111111111111111111111111111111111
  =>41152263004115226300411522630/11111111111111111111111111111111111111

-----

1 point by shader 5817 days ago | link

You could make your own number data type. Have a cons cell in which both halves are bignums, the car being the mantissa and the cdr being the exponent. You would have to overload the math functions for you datatype of course, or write your own set for use in this circumstance.

-----

1 point by thaddeus 5830 days ago | link

I see. I'd imagine when you work with numbers this large it probably doesn't make sense to have them run on forever in decimal format anyway. I'm just not used to working in rationals yet. Thanks! :)

-----

1 point by thaddeus 5830 days ago | link

Needs to stay as a number not a string :)

-----