Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何获得第二个小数位0?
例如:
15.296326 => 15.30 15.245152 => 15.20
我已经尝试过toFixed(),Math.Floor但无法得到预期的答案。
toFixed()
Math.Floor
function roundFloat(n) { return (Math.round(n * 10) / 10).toFixed(2); } roundFloat(15.296326); // "15.30" roundFloat(15.245152); // "15.20"