Home  >  Article  >  Web Front-end  >  js amount processing plus two decimal places

js amount processing plus two decimal places

不言
不言Original
2018-07-09 17:22:062671browse

This article mainly introduces the js amount processing plus two decimal places, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

function toDecimal2(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return false;
        }
        var f = Math.round(x*100)/100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
            rs = s.length;
            s += &#39;.&#39;;
        }
        while (s.length <= rs + 2) {
            s += &#39;0&#39;;
        }
        return s;
    }

The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

js time and millisecond conversion

js moves any element to the specified position

About the implementation of JS effect function

The above is the detailed content of js amount processing plus two decimal places. For more information, please follow other related articles on the PHP Chinese website!

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