Home > database >  Can I restrict numbers to only 3 decimals globally in Haskell?
Can I restrict numbers to only 3 decimals globally in Haskell?

Time:10-05

I have a package which generates SVG code (images and icons)

However, the resulting svg code is too large because all numbers have lots of decimal places.

Is there a language pragma or anything similar that I can do to restrict all numbers to only have 3 decimal digits?

I would like to do this with some minimal code, I do not want to apply some function to every Float number individually.

CodePudding user response:

No, you can't change how IEEE 754 floating point arithmetic works. That change would probably affect a lot more than you expect, anyway. Fortunately, what you want is not to change how floats are represented, but how they are presented. So you only have to change the code that actually writes floats to the output file, not all code that touches floats.

  • Related