簡體   English   中英

Javascript或Jquery舍入到小數點后1位

[英]Javascript or Jquery rounding up to 1 decimal place

我需要舍入到小數點后1位

如果我的號碼是80.02,我需要它是80.1。

試着

Math.ceil( (80.02).toFixed(1) ) but this rounds the number up to 81

我怎樣才能做到這一點?

使用Math.ceil( number * 10 ) / 10; 四舍五入

將它固定到一個小數位

(Math.ceil( number * 10 ) / 10).toFixed(1);

工作小提琴

你應該使用地板而不是ceil

Math.floor( (80.02).toFixed(1) )

Math.round將在> = x.5處向上舍入並向下舍入<x.5

.ceil四舍五入到下一個數字

.floor向下舍入到下一個數字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM