[已解决]AU3正则替换数字为逗号分隔符
本帖最后由 dhlhmgc 于 2013-3-14 09:16 编辑Dim $n,$c,$v
$n = "-1279834847944074100465236.3398"
$c = StringRegExpReplace($n,"(\d{1,3})(?=(\d{3})+(?:$|\.))","$1,")
$v = StringRegExpReplace($n,"[^0-9.-]","")
msgbox(4096,"结果",StringFormat("原值: %40s\n格式: %40s\n转回: %40s",$n,$c,$v) )
此段代码将数字格式化为日常货币格式,也可转回,但测试中存在一下问题,
就是小数点后超过三位时,也会加入逗号分隔符,期待高人指点一下!
如何改进 "(\d{1,3})(?=(\d{3})+(\.\d*)+(?:$|\.))","$1,") 本帖最后由 shqf 于 2013-3-13 15:50 编辑
Dim $n, $c, $v
$n = "-1279834847944074100465236.3398"
$c = StringRegExpReplace($n, "(?<=\d)(?=((\d{3})+\.))", ",")
$v = StringRegExpReplace($c, ",", "")
MsgBox(4096, "结果", StringFormat("原值: %40s\n格式: %40s\n转回: %40s", $n, $c, $v)) 测试没有问题,多谢指点!
要能有点说明就更好了! 测试没有问题,多谢指点!
要能有点说明就更好了!
dhlhmgc 发表于 2013-3-14 09:16 http://www.autoitx.com/images/common/back.gif
不带小数的话就都有问题了…
页:
[1]