Javascript 四舍五入货币/数字(jqGrid)

Javascript 四舍五入货币/数字(jqGrid),javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,我有一个网格,输入一个数字,例如15.32 如何将此数字四舍五入到16.00 如果我有16.01,我想把它四舍五入到17.00。这个数字总是四舍五入 { label:'Summ', name:'f4', index:'f4', width:120, search: false, formatter:'currency', formatoptions:{defaulValue:0,thousandsSeparator:' ',decimalP

我有一个网格,输入一个数字,例如
15.32

如何将此数字四舍五入到
16.00

如果我有
16.01
,我想把它四舍五入到
17.00
。这个数字总是四舍五入

{
    label:'Summ',
    name:'f4',
    index:'f4',
    width:120,
    search: false,
    formatter:'currency',
    formatoptions:{defaulValue:0,thousandsSeparator:' ',decimalPlaces:2,suffix:'$'}
},

您可以使用自定义格式化程序来实现这一点,该格式化程序同时包含数字值和后缀。 例如:

// Custom formatter that ceils all number values and suffixes .00$
function myCurrencyFormatter (cellvalue, options, rowObject)
{
    if(cellvalue == undefined) return "0.00$";
    else return Math.ceil(cellvalue) + ".00$";
}

{
    label: "Sunm",
    name:'f4',
    index:'f4',
    width:120,
    search: false,
    // Uses the custom formatter
    formatter: myCurrencyFormatter,
}
您可以在这里尝试:

我更新了fiddler版本,使其也可以处理千分表.Thx。我能做到:)但是现在。。。f4=资金*资金投票/100//资金和资金投票-是一个值,我的下一个值是“f5”,其中f5=f4+总票数,这里我看不到。。。我必须为每个耳朵写函数吗?也许我可以只写一个,而join标签是输出给我正确的P.S.抱歉英语不好:((不,您可以通过将“formatter”选项设置为“myCurrencyFormatter”,对任何货币列重复使用相同的函数).我是否正确理解了您的问题?我现在为每个人设置了格式化程序:myCurrencyFormatter hm…我无法设置问题..我有第二个问题如何使用此选项defaulValue:0,千分位:'',小数点:2,后缀:'$'检查fiddle链接,应该在代码中解释所有内容