+ 2
How i can Separate the three digits of the three digits into the calculator program output. For easier readability numbers. Py
useless from split and list
15 Respuestas
+ 3
@Ulisses Cruz: << @visph you method will fail if the number has 6 digits. It will add 2 commas. >>
It's not fail, it's the expected result... in my mind at least (in France, we separate each 3 digits groups with a dot, as the comma is used for the floating point, but we put one at each separation group ^^)
+ 3
I understand now... and I confess having not tested a lot (just the number in code) :P
Anyway, the fix is obvious, even if it require an additionnal line/test ;)
+ 2
Without knowing to wich language your question is related, it's difficult to answer you ^^
Anyway, one way could be to cast your number to string, and add a space each 3 digit, starting from right to left (from last index of string to first)...
Pseudo code:
str numtext = str(num);
int i = numtext.length();
str formatednum = '';
while (i--) {
formatednum = numtext[i] + formatednum;
if ((numtext.length()i)%3==0) { formatednum = ' ' + formatednum; }
}
+ 2
Python code
num = 42256
numtext = str(num)
formatednum = ''
mx = len(numtext)
for i in range(mx-1,-1,-1):
formatednum = numtext[i] + formatednum
if (mx-i)%3 == 0:
formatednum = ',' + formatednum
print(formatednum)
+ 2
yeah ulisses cruz . ex: 10000 to 1000,00
+ 2
ulisses cruz It was fantastic. Thank you so much
+ 1
ulisses cruz i want for python
+ 1
@ulisses cruz Separating numbers in the output of all three digits with "," pleaz help me
+ 1
visph thanks bro
+ 1
Here is a simpler method:
https://code.sololearn.com/cjVmJ6zePGNO/?ref=app
+ 1
@visph you method will fail if the number has 6 digits. It will add 2 commas.
0
Do you mean, if the output is 10000 to separate it like this: 10,000 ?
0
Sorry @visph,
you are right. Fail is not the correct word.
What I wanted to say is that it will not produce the correct output.
Here is what I'm refering to:
https://code.sololearn.com/c0291p30cgj5/?ref=app
- 1
Hello @mostafa,
Can you explain your question better please?
- 1
But I did not understand the question.
Can you explain?