Round just decimal in Javascript
问题 I have a value like that: 20.93 I'd like to round it to 20.90 How can I do that in Javascript ? Thanks! 回答1: Multiply the number by 10, round it and then divide the number by 10: var result = Math.round(20.93 * 10) / 10 回答2: I think this should work: number .toFixed(1); 回答3: var num= 20.93 num = Math.floor(num * 10) / 10; // 20.9 num = Math.ceil(num * 10) / 10; //21 回答4: I take it that you want the trailing zero. None of the answers give you that. It has to be a String to have the trailing