有一列数字,例如:
在整个列中。 我在许多论坛中都找不到简单的解决方案。我该如何实现它?
ex.
12876391
希望进行转换
12,876,391
在整个列中。 我在许多论坛中都找不到简单的解决方案。我该如何实现它?
提醒一下 - @JSmart523 提供的解决方案很好,但有一个错误。最后一行应该是 List.Count(numberAsTextList) = 1,所以完整的代码如下:
(n as number) as text => let numberAsTextList = Text.Split(Number.ToText(Number.Abs(n), null, "en-US"), "."), textWhole = numberAsTextList{0}, fNextRecordInListGenerate = each let len = Text.Length([remaining]) in if len = 0 then [remaining = null] else [remaining = Text.Start([remaining], List.Max({0, len - 3})), part = Text.End([remaining], 3)], nums = List.Reverse(List.Generate( () => fNextRecordInListGenerate([remaining = textWhole, part = ""]), each [remaining] null, fNextRecordInListGenerate, each [part] )), ret = (if Number.Sign(n) = -1 then "-" else "") & Text.Combine(nums, ",") & (if List.Count(numberAsTextList) = 1 then "" else "." & numberAsTextList{1}) in ret
(n as number) as text =>
let
numberAsTextList = Text.Split(Number.ToText(Number.Abs(n), null, "en-US"), "."),
textWhole = numberAsTextList{0},
fNextRecordInListGenerate = each
let
len = Text.Length([remaining])
in
if len = 0 then
[remaining = null]
else
[remaining = Text.Start([remaining], List.Max({0, len - 3})), part = Text.End([remaining], 3)],
nums = List.Reverse(List.Generate(
() => fNextRecordInListGenerate([remaining = textWhole, part = ""]),
each [remaining] <> null,
fNextRecordInListGenerate,
each [part]
)),
ret = (if Number.Sign(n) = -1 then "-" else "")
& Text.Combine(nums, ",")
& (if List.Count = 1 then "" else "." & numberAsTextList{1})
in
ret