一个整数值的千位分隔符 [英] Thousands separator of an integer value
问题描述
让我们说我有这在我的批处理文件:
Let's say I have this in my batch file:
set var1=12345
和我想在第一个变量的(VAR1)添加逗号并将其保存到另一个变量的(VAR2)
And I want to add commas in the first variable (var1) and save it to another variable (var2).
这意味着,第二个变量的(VAR2)应该有这个值: 12345
That means that the second variable (var2) should have this value: 12,345.
因此,如果第一个变量(VAR1)有这个价值:123456789,第二个的(VAR2)值必须123,456,789
So If the first variable (var1) had this value: 123456789, the second one's (var2) value has to be 123,456,789.
任何想法?
编辑:
我不希望PowerShell命令,因为没有为我工作。
请写的没有的PowerShell。
I don't want PowerShell commands because the don't work for me. Please write without PowerShell.
推荐答案
另外一个!
@echo off
setlocal EnableDelayedExpansion
set "var1=%1"
echo First variable: %var1%
set "var2="
set "sign="
if "%var1:~0,1%" equ "-" set "sign=-" & set "var1=%var1:~1%"
for /L %%i in (1,1,4) do if defined var1 (
set "var2=,!var1:~-3!!var2!"
set "var1=!var1:~0,-3!"
)
set "var2=%sign%%var2:~1%
echo Second variable: %var2%
如果你想增加的位数,只是增加组数在为
命令值大于4。
If you want to increase the number of digits, just increase the number of groups in the for
command to a value greater than 4.
这篇关于一个整数值的千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!