有什么方法可以更改 ColdFusion 中 LSCurrencyFormat 的舍入方法吗?
ColdFusion 的 LSCurrencyFormat 函数似乎使用舍入到半偶数(银行舍入)。有办法改变这个吗?我想将其更改为大多数人在小学所教的标准四舍五入。
示例:
LSCurrencyFormat(39.7340): $39.73
LSCurrencyFormat(39.7350):39.74 美元
LSCurrencyFormat(39.7360): $39.74
LSCurrencyFormat(39.7440): $39.74
LSCurrencyFormat(39.7450):$39.74 <==我希望这是 $39.75
LSCurrencyFormat(39.7460): $39.75
ColdFusion's LSCurrencyFormat function appears to be using round-to-half-even (banker's rounding). Is there anyway to change this? I'd like to change it to standard round-half-up rounding that most people are taught in grade school.
An example:
LSCurrencyFormat(39.7340): $39.73
LSCurrencyFormat(39.7350): $39.74
LSCurrencyFormat(39.7360): $39.74
LSCurrencyFormat(39.7440): $39.74
LSCurrencyFormat(39.7450): $39.74 <== I want this to be $39.75
LSCurrencyFormat(39.7460): $39.75
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为没有办法自定义数字函数使用的舍入模式。 (虽然我可能是错的)您可能必须深入研究java来定制舍入行为
更新我的错误。我认为需要的是一些基本面具尚未提供的东西。那好吧。也许这个例子对某人还是有用的..
更新添加了HALF_UP 舍入模式 示例
(注意:区域设置处理既快又脏。我确信有一种更优雅的方法来做到这一点..)
I do not think there is a way to customize the rounding mode used by the numeric functions. (Though I could be wrong) You may have to dip into java for customized rounding behavior
Update My mistake. I thought the need was for something basic masks did not already provide. Oh, well. Maybe this example will be useful to someone anyway ..
Update Added HALF_UP rounding mode example
(Note: The Locale handling is quick and dirty. I am sure there is a more elegant way of doing it..)
尝试使用掩码 LSNumberFormat()
Try LSNumberFormat() with a mask
为什么在将值发送到 LSCurrencyFormat 之前不进行舍入?
Why not round before you send the value to the LSCurrencyFormat?
另请参阅 http://jamiekrug.com/blog/index.cfm/2009/2/12/ColdFusion-round-function-bug-when-operation-performed-on-argument
Also see http://jamiekrug.com/blog/index.cfm/2009/2/12/ColdFusion-round-function-bug-when-operation-performed-on-argument