插件-逗号小数 [英] Plugin - comma decimals

查看:75
本文介绍了插件-逗号小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个价格表,格式为:"1.234,56"(千位分隔符是一个句点,十进制分隔符是一个逗号).这种格式不起作用,因为只要内部有一个不同的字符(仅允许数字,+/-和."代表小数),tablesorter插件会将其视为字符串而不是数字.

I have a table with prices in this format: "1.234,56", (the thousands separator is a period, and the decimal separator is a comma). This format doesn't work because tablesorter plugin sees it as strings rather than as a number whenever there's a different character inside (only numbers, +/- and "." for decimals are allowed).

如何在排序之前删除句点并用句点替换逗号?

How can I remove the periods and replace the commas with periods before sorting?

推荐答案

好的,我想我已经解决了.我的表有货币,所以我编辑了货币"解析器,但基本上可以与其他任何货币一起使用.货币解析器最后看起来像这样:

Ok, I think I solved it. My table has currency so I edited the 'currency' parser but you could basically do it with any other. Currency parser looks like this in the end:

ts.addParser({
    id: "currency",
    is: function(s) {
        return /^[£$€?.]/.test(s);
    },
    format: function(s) {
        s=s.replace('.', '');
        return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));
    },
    type: "numeric"
});

(顺便说一句,如何在stackoverflow上打开synthax高亮显示?)

(by the way, how do you turn on synthax highlight here on stackoverflow?)

这篇关于插件-逗号小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆