如何用数千个分隔符排序数字 [英] How to sort a number with thousands separator

查看:195
本文介绍了如何用数千个分隔符排序数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用 jQuery Datatables插件对数字进行排序,但不能使用C#字符串数字格式。

I have tried to sort the number with jQuery Datatables plug-in but is not working with C# string number formats.

我尝试过:

decimal value= 12345678.00
value..ToString("#,##.00");
value.ToString("##,##.##");
value.ToString("0,0.00", CultureInfo.InvariantCulture)

但没有运气因为逗号。如果没有逗号是正常工作,或者所有具有相同计数的数字也正在工作,即

but no luck because of the comma. If there is no comma is works fine or all the numbers with same count also working i.e.


01,121,372.01

01,121,372.01

02,002,009.22

02,002,009.22

11,222,222,33

11,222,222,33

如果如下所示,它不工作

If it is as below then it is not working


1,111,111.11

1,111,111.11

222,191.00

222,191.00

32,222.00

32,222.00


推荐答案

这是为了克服这个问题。

I have done like this to overcome to this issue.

"aoColumnDefs": [ {
                    "aTargets": [3,4,6],
                    "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                        var $currencyCell = $(nTd);
                        var commaValue = $currencyCell.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
                        $currencyCell.text(commaValue);
                    }
                }]

这篇关于如何用数千个分隔符排序数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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