Re: [Haskell-cafe] How to round off frational number?
Thanks a lot. That's what I need. On 9/8/06, J. Garrett Morris [EMAIL PROTECTED] wrote: I've always used: roundn n f = fromIntegral (round (f * 10 ^ n)) / 10 ^ n I may have missed some bugs or subtleties of floating point numbers, though. /g On 9/8/06, Sara Kenedy [EMAIL PROTECTED] wrote: Hello all, I try to find some functions in Haskell library to deal with numeric such that the result in the following format (but I did not find) For example, 1/3 0.33 1/6 0.17 8/3 2.67 9/3 3.00 It seems a so baby question, but I really did not find the answer after trying on that for some hours. Thanks for any help. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- It is myself I have never met, whose face is pasted on the underside of my mind. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to round off frational number?
Hello all, I try to find some functions in Haskell library to deal with numeric such that the result in the following format (but I did not find) For example, 1/3 0.33 1/6 0.17 8/3 2.67 9/3 3.00 It seems a so baby question, but I really did not find the answer after trying on that for some hours. Thanks for any help. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to round off frational number?
I've always used: roundn n f = fromIntegral (round (f * 10 ^ n)) / 10 ^ n I may have missed some bugs or subtleties of floating point numbers, though. /g On 9/8/06, Sara Kenedy [EMAIL PROTECTED] wrote: Hello all, I try to find some functions in Haskell library to deal with numeric such that the result in the following format (but I did not find) For example, 1/3 0.33 1/6 0.17 8/3 2.67 9/3 3.00 It seems a so baby question, but I really did not find the answer after trying on that for some hours. Thanks for any help. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- It is myself I have never met, whose face is pasted on the underside of my mind. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to round off frational number?
On 9/8/06, Sara Kenedy [EMAIL PROTECTED] wrote: I try to find some functions in Haskell library to deal with numeric such that the result in the following format (but I did not find) For example, 1/3 0.33 You're talking about a number-to-string conversion, right? You probably want showFFloat, from the Numeric module. There's also the Text.Printf module. Or you could write your own display code; but it's tricky to get it right for every possible case. http://haskell.org/ghc/docs/latest/html/libraries/base/Numeric.html#v%3AshowFFloat Hope this helps! --Tom Phoenix ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe