Skip to main content

Timeline for answer to Limiting floats to two decimal points by Xolve

Current License: CC BY-SA 4.0

Post Revisions

19 events
when toggle format what by license comment
S Mar 29, 2020 at 18:51 history suggested LeBorgne CC BY-SA 4.0
Remove positional argument for genericity
Mar 29, 2020 at 16:44 review Suggested edits
S Mar 29, 2020 at 18:51
Feb 20, 2019 at 12:54 comment added Andrey Semakin By the way, since Python 3.6 we can use f-strings: f"Result is {result:.2f}"
May 25, 2018 at 22:41 history edited Peter Mortensen CC BY-SA 4.0
Active reading.
Nov 15, 2017 at 18:33 comment added AlejandroVD Notice that if you want to format more than one number, you need to increment the integer before the colon: >>> print("{0:.2f} - {0:.2f}".format(.1234, .5678)) 0.12 - 0.12 >>> print("{0:.2f} - {1:.2f}".format(.1234, .5678)) 0.12 - 0.57
S Oct 23, 2017 at 14:53 history edited Xolve CC BY-SA 3.0
Added Hyperlink
S Oct 23, 2017 at 14:53 history suggested Altay Akkus CC BY-SA 3.0
Added Hyperlink
Oct 23, 2017 at 14:37 review Suggested edits
S Oct 23, 2017 at 14:53
Oct 8, 2017 at 3:43 comment added Xolve @NeilChowdhury True, I asked me same after writing the answer. Assumption of question is to display float where to two decimal places.
Oct 7, 2017 at 21:41 comment added Neil There's no way to "round" a number. Formatting is just for pretty-printing. If you really need to store the digits (e.g. keeping track of money) use integers.
Sep 12, 2014 at 22:50 history edited jgritty CC BY-SA 3.0
edited body
Aug 17, 2014 at 14:09 comment added Jossef Kadouri @NedBatchelder: i agree that they are equal, but this limits the float to two decimal points :)
Aug 17, 2014 at 13:57 history edited Ned Batchelder CC BY-SA 3.0
added 286 characters in body
Aug 17, 2014 at 13:52 comment added Ned Batchelder @JossefHarush you can wrap it with float(), but you haven't gained anything. Now you have a float again, with all the same imprecision. 13.9499999999999 and 13.95 are the same float.
S Aug 17, 2014 at 13:33 history suggested Jossef Kadouri CC BY-SA 3.0
added note from comments
Aug 17, 2014 at 13:26 review Suggested edits
S Aug 17, 2014 at 13:33
Aug 17, 2014 at 13:22 comment added Jossef Kadouri @OnurYıldırım: yes, but you can wrap it with float(); float("{0:.2f}".format(13.9499999))
Jun 20, 2014 at 2:41 comment added Stephen Blum to add commas as well you can '{0:,.2f}'.format(1333.949999999) which prints '1,333.95'.
Jun 30, 2011 at 18:53 history answered Xolve CC BY-SA 3.0