Rounding numbers to 2 digits after comma

前端 未结 8 1220
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 12:14

I have no idea how to do this? I\'m adding comma numbers, result is of course always a number with way too many digits after the comma. anyone?

8条回答
  •  臣服心动
    2020-11-28 12:55

    This worked for me:

    var new_number = float.toFixed(2);
    

    Example:

    var my_float = 0.6666
    
    my_float.toFixed(3) # => 0.667
    

提交回复
热议问题