Haskell:强制浮点数有两位小数 [英] Haskell: Force floats to have two decimals

查看:103
本文介绍了Haskell:强制浮点数有两位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码片段:

 (fromIntegral 100)/10.00 



使用Haskell '98标准前奏,我如何用两位小数表示结果?


解决方案

只为记录:

  import数字
formatFloatN floatNum numOfDecimals = showFFloat(只是numOfDecimals)floatNum


Using the following code snippet:

(fromIntegral 100)/10.00

Using the Haskell '98 standard prelude, how do I represent the result with two decimals?

Thanks.

解决方案

Just for the record:

import Numeric 
formatFloatN floatNum numOfDecimals = showFFloat (Just numOfDecimals) floatNum ""

这篇关于Haskell:强制浮点数有两位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆