Home
Web Front-end
JS Tutorial
js amount formatting and round-trip conversion example_javascript skills



js amount formatting and round-trip conversion example_javascript skills
May 16, 2016 pm 04:58 PM
Convert
Let’s look at the example directly:
Copy the code The code is as follows:
function fmoney(s, n) //s: the float number passed in, n: the number of decimal points you want to return
{
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s "").replace(/[^d.-]/g, "")).toFixed(n) "";
var l = s.split(".")[0].split("" ).reverse(),
r = s.split(".")[1];
t = "";
for(i = 0; i < l.length; i )
{
t = l[i] ((i 1) % 3 == 0 && (i 1) != l.length ? "," : "");
}
return t .split("").reverse().join("") "." r;
}
The function of this function is to
call: fmoney(" 12345.675910", 3), returns 12,345.676
Copy code The code is as follows:
function rmoney(s )
{
return parseFloat(s.replace(/[^d.-]/g, ""));
}
Format the amount returned above The number is returned as float type.
Copy code The code is as follows:
rmoney(12,345.676) //The return result is: 12345.676
Statement of this Website
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

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

A simple guide to converting USDT ERC20 to TRC20

Practical tips for converting full-width English letters into half-width form

How to convert ODT to Word in Windows 11/10?

How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone

Golang time processing: How to convert timestamp to string in Golang

How to convert AI files to CDR format

How to convert a virtual machine to a physical machine?

Detailed explanation of the implementation method of converting PHP months to English months
