我从数据库中获取一笔金额并使用该金额填充一个显示进度捐赠温度计的js脚本。
Current Dontations: <?php
global $wpdb;
$results = $wpdb->get_results('SELECT SUM(purchase_value) AS sum_total FROM wp_cmxi_edd_customers');
$var ='$total';
$total = 0;
foreach ($results as $result):
$total = $result->sum_total;
break;
endforeach;
?>
<tr>
<td><?php echo $total;?></td>
</tr>
js:
<script type="text/javascript">
var currentAmount = '<?php echo $var ;?>';
</script>
问题是,它返回NaN因为我需要对数字进行舍入以删除小数。你如何在同一时间转换和SUM?