Round number to specified number of digits

后端 未结 3 1549
甜味超标
甜味超标 2021-02-07 01:57

Is there a simple function to round a Double or Float to a specified number of digits? I\'ve searched here and on Hoogle (for (Fractional a) =>

3条回答
  •  情深已故
    2021-02-07 02:44

    It depends on what you are going to do with the rounded number.

    If you want to use it in calculations, you should use Data.Decimal from Decimal library.

    If you want just to format the number nicely, you should use Text.Printf from the standard library (base package).

提交回复
热议问题