{{number_format(floor($item[0]->price), 0, '.', ' ')}}
<sup class="price_dec">
,{{str_replace("0.","",(string)number_format(round($item[0]->price - (int)$item[0]->price,2),2))}}
</sup
如何在Jquery中转换PHP代码?
<span style='font-size:25px'>180</span>,90 $ <br>
<span style='font-size:25px'>1 100</span>,90 $ <br>
<span style='font-size:25px'>100 000</span>,90 $ <br>
<span style='font-size:25px'>1 000 000</span>,90 $ <br>
也许这段代码可以是一个解决方案 我使用带小数的数字只是为了显示函数舍入数字的方式
<html>
<head>
<script>
// this is document ready
document.addEventListener("DOMContentLoaded", function(){
// Because number_format does not exist, you must create a function
Number.prototype.number_format = function(n, s, c, x)
{
/**
* Number.prototype.format(n, s, c, x)
*
* @param integer n: length of decimal
* @param mixed s: sections delimiter
* @param mixed c: decimal delimiter
* @param integer x: length of whole part
*/
// Defaults
s = s || ".";
c = c || ",";
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
num = this.toFixed(Math.max(0, ~~n));
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};
// Let assume that you have an array of numbers
var prices = [180.912, 1100.954, 100000.955, 1000000.956];
var string = "";
var match = [];
var pattern = /,[0-9]{2}\s\$/g
var regex = new RegExp(pattern);
var element = document.getElementsByTagName("body")[0];
for(i in prices) {
string = "<div>"+ prices[i].number_format(2, " ", ",", 3) +" $<div>";
match = string.match(regex)
string = string.replace(match[0], "<small>"+ match[0] +"<small>")
element.innerHTML += string;
}
});
</script>
</head>
<body>
</body>
</html>