Forum » Programiranje » [Python] Kako pretvorit string število da bo imelo vejce in piko?
[Python] Kako pretvorit string število da bo imelo vejce in piko?
![](https://static.slo-tech.com/stili/avatar_gray.gif)
HotBurek ::
Dobro jutro.
Imam dokaj preprost problem.
Input je string "12345672.4". Za output bi želel, pa da je "12,345,672.40". Se pravi, da se cente zapiše z dvema ciframa, ter da je na vsakih tri vejica.
Trenutni sample:
Output:
Na koncu ni gut, ker fali nula. Se pravi, želel bi, da je: 12,345,672.40.
Imam dokaj preprost problem.
Input je string "12345672.4". Za output bi želel, pa da je "12,345,672.40". Se pravi, da se cente zapiše z dvema ciframa, ter da je na vsakih tri vejica.
Trenutni sample:
value = "12345672.4"; print(value); value = "{:.2f}".format(float(value)); print(value); value = "{:,}".format(float(value)); print(value);
Output:
12345672.4 12345672.40 12,345,672.4
Na koncu ni gut, ker fali nula. Se pravi, želel bi, da je: 12,345,672.40.
root@debian:/# iptraf-ng
fatal: This program requires a screen size of at least 80 columns by 24 lines
Please resize your window
fatal: This program requires a screen size of at least 80 columns by 24 lines
Please resize your window
![](https://static.slo-tech.com/stili/avatar_gray.gif)
HotBurek ::
Bom ker odgovoril.
Takoj, ko sem vnesel temo, sem probal, kaj bi se zgodilo, če oboje skup vnesem. In je ratal.
Rešitev:
Output:
Well done.
Takoj, ko sem vnesel temo, sem probal, kaj bi se zgodilo, če oboje skup vnesem. In je ratal.
Rešitev:
value = "12345672.4"; print(value); value = "{:,.2f}".format(float(value)); print(value);
Output:
12345672.4 12,345,672.40
Well done.
root@debian:/# iptraf-ng
fatal: This program requires a screen size of at least 80 columns by 24 lines
Please resize your window
fatal: This program requires a screen size of at least 80 columns by 24 lines
Please resize your window
Zgodovina sprememb…
- spremenilo: HotBurek ()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | python-rabim pomočOddelek: Programiranje | 2815 (1045) | rnla1973 |
» | Pomoč C++Oddelek: Pomoč in nasveti | 1382 (1101) | samo111 |
» | Kontakt obrazecOddelek: Izdelava spletišč | 2085 (1930) | betmen |
» | [Java] Objekt poslan k metodi v kakšnem stanju?Oddelek: Programiranje | 1604 (1051) | shadeX |
» | [C#] toString ne delaOddelek: Programiranje | 1347 (1237) | rokpok |