<script type="text/javascript">
function changeDecimalBuZero(number, bitNum) {
/// <summary>
/// 小数位不够,用0补足位数
/// </summary>
/// <param name="number">要处理的数字</param>
/// <param name="bitNum">生成的小数位数</param>
var f_x = parseFloat(number);
if (isNaN(f_x)) {
return 0;
}
var s_x = number.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + bitNum) {
s_x += '0';
}
return s_x;
}
</script>
js将小数位不够补足,小数位不够,用0补足位数
本文转载:CSDN博客