+ 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

14th Jun 2017, 11:47 PM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
15 Antworten
+ 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 ^^)
15th Jun 2017, 12:33 AM
visph
visph - avatar
+ 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 ;)
15th Jun 2017, 12:44 AM
visph
visph - avatar
+ 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; } }
15th Jun 2017, 12:01 AM
visph
visph - avatar
+ 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)
15th Jun 2017, 12:18 AM
visph
visph - avatar
+ 2
yeah ulisses cruz . ex: 10000 to 1000,00
15th Jun 2017, 12:19 AM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
+ 2
ulisses cruz It was fantastic. Thank you so much
15th Jun 2017, 12:30 AM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
+ 1
ulisses cruz i want for python
15th Jun 2017, 12:04 AM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
+ 1
@ulisses cruz Separating numbers in the output of all three digits with "," pleaz help me
15th Jun 2017, 12:13 AM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
+ 1
visph thanks bro
15th Jun 2017, 12:20 AM
mostafa_iran_dezfoul
mostafa_iran_dezfoul - avatar
15th Jun 2017, 12:25 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
@visph you method will fail if the number has 6 digits. It will add 2 commas.
15th Jun 2017, 12:28 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
Do you mean, if the output is 10000 to separate it like this: 10,000 ?
15th Jun 2017, 12:17 AM
Ulisses Cruz
Ulisses Cruz - avatar
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
15th Jun 2017, 12:38 AM
Ulisses Cruz
Ulisses Cruz - avatar
- 1
Hello @mostafa, Can you explain your question better please?
15th Jun 2017, 12:01 AM
Ulisses Cruz
Ulisses Cruz - avatar
- 1
But I did not understand the question. Can you explain?
15th Jun 2017, 12:09 AM
Ulisses Cruz
Ulisses Cruz - avatar