Round number to specified number of digits

后端 未结 3 1548
甜味超标
甜味超标 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:54

    Not sure whether any standard function exists, but you can do it this way:

     (fromInteger $ round $ f * (10^n)) / (10.0^^n)
    

提交回复
热议问题