Input value variable price = 6811.15;
var strPrice = number_format(parseFloat(price),2);
console.log(strPrice); // 6,811,.15
Invalid value 6811.15 -> number_format -> 6,811,15
Expected value 6811.15 -> number_format -> 6,811.15
The value is strange even if you apply Math.round and .fixed(2) in this way.
javascript jquery html
Is number_format a self-made function?
Do it like this.
Number.prototype.numberFormat = function(c){
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? (i.substr(0, j) + ",") : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + ",") + (c ? "." + Math.abs(n - i).toFixed(c).slice(2) : "");
};
var price = 6811.15;
var strPrice = (6811.15).numberFormat(2)
console.log(strPrice); // 6,811,.15
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
572 Understanding How to Configure Google API Key
577 PHP ssh2_scp_send fails to send files as intended
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.