需要帮助我的代码
save_method = 'update';
$('#form')[0].reset(); // reset form on modals
$('.form-group').removeClass('has-error'); // clear error class
$('.help-block').empty(); // clear error string
//Ajax Load data from ajax
$.ajax({
url : "<?php echo site_url('info/ajax_detail')?>/" + Kode,
type: "GET",
dataType: "JSON",
success: function(data)
{
var data = '<td><center>'+data.total+'</center></td>';
data += '<td><center>'+data.subtotal+'</center></td></tr>';
$('#table tbody').html(tbaris);
$('#modal_form1').modal('show'); // show bootstrap modal when complete loaded
$('.modal-title').text('SEE DEtail'); // Set title to Bootstrap modal title
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error get data from ajax');
}
如何使用此代码将数字格式设置到我的ajax
var data = '<td><center>'+data.total+'</center></td>';
data += '<td><center>'+data.subtotal+'</center>
生病尝试使用此代码但无法正常工作
data = '<td><center>'.number_format("+data.total+",2,",",".").'</center>
data += '<td><center>'.number_format("+data.total+",2,",",".").'</center>
答案 0 :(得分:0)
首先您需要添加numberformat.js
脚本,请参阅Gist
使用数字格式功能可以转换它
对于所需的输出,请遵循模式
//英文格式
number_format( 1234.50, 2, '.', ',' ); // ~> "1,234.50"
//德语格式
number_format( 1234.50, 2, ',', '.' ); // ~> "1.234,50"
//法语格式
number_format( 1234.50, 2, '.', ' ' ); // ~> "1 234.50"
或只是在脚本中添加功能
function number_format(number, decimals, decPoint, thousandsSep){
decimals = decimals || 0;
number = parseFloat(number);
if(!decPoint || !thousandsSep){
decPoint = '.';
thousandsSep = ',';
}
var roundedNumber = Math.round( Math.abs( number ) * ('1e' + decimals) ) + '';
var numbersString = decimals ? roundedNumber.slice(0, decimals * -1) : roundedNumber;
var decimalsString = decimals ? roundedNumber.slice(decimals * -1) : '';
var formattedNumber = "";
while(numbersString.length > 3){
formattedNumber += thousandsSep + numbersString.slice(-3)
numbersString = numbersString.slice(0,-3);
}
return (number < 0 ? '-' : '') + numbersString + formattedNumber + (decimalsString ? (decPoint + decimalsString) : '');
}
检查jsfiddle上的样本