Home  >  Article  >  Web Front-end  >  Keep to one decimal place without rounding

Keep to one decimal place without rounding

巴扎黑
巴扎黑Original
2016-12-10 09:09:521855browse

Retain one significant figure without rounding;

For example: 199.999

is processed as follows

var str = parseFloat(199.999).toFixed(10);//Write 10 here to ensure that several decimal places are retained, after it The little one’s number is 0 without rounding, so the result is what you want

var num = str.substring(0,str.lastIndexOf('.')+2) +"万";

After the following processing, num becomes 199.9


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:JS real-time timeNext article:JS real-time time