• Status: Solved
• Priority: Medium
• Security: Public
• Views: 268

# mil & thousand Seperation of numbers

Can anyone offer the easiest way to seperate numbers by tousand, millions, etc.
For Example:

I have a variable which is called \$money
e.g. The variable takes the values: 10000 or 250000 or 4500332.

now the values should be changed to: 10 000 or 250 000 or 4 500 332
(thousand steps seperated with spaces)

I need a fast and easy solution for a variable which can be any number from 100 to 10000000
(unknown number of digits).

Mfuerlinger
0
mfuerlinger
• 2
1 Solution

Commented:
you can use "_" and perl will trat it as digit :

10 000 or 250 000 or 4 500 332

10_000 or 250_000 or 4_500_332

if that is what you want ...

:)

or... if have 4500332 and you want to make it 4 500 332
\$money = "4500332";
\$money_pretty = reverse join " ",  split (/(\d{3})/, reverse \$money);
print \$money_pretty;

:)
0

Commented:
perldoc -q "How can I output my numbers with commas added?"

0

Commented:
\$a=12345678;
while (\$a =~ s/([0-9]+)([0-9][0-9][0-9])((" "[0-9][0-9][0-9])*)/\$1 \$2\$3/){};
print "Fim: \$a\n";
0

Commented:
Ha Ha Ha   ::)))))))))

very good  !!!

:::))))))))))))))))))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.