如何四舍五入到小数点后两位? [英] How do I round to 2 decimal places?

查看:87
本文介绍了如何四舍五入到小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带逗号的数字,例如:254,5.我需要在,5后面的0,所以它看起来像254,50.

I have a number with a comma, for example: 254,5. I need the 0 behind the ,5 so it stands like 254,50 instead..

我正在使用它来获取号码:

I'm using this to get the number:

Math.floor(iAlt / 50) * 50;

如何将0放在,5后面?

推荐答案

尝试 A Number将始终删除尾随零,因此toFixed返回String.

A Number will always remove trailing zeros, so toFixed returns a String.

请务必注意,必须在号码上呼叫toFixed .调用 parseFloat()

It's important to note that toFixed must be called on a number. Call parseFloat() or parseInt() to convert a string to a number first, if required (not in this situation, but for future reference).

这篇关于如何四舍五入到小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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