Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rounding question
#5
(Apr-11-2020, 08:41 AM)DPaul Wrote: But you don't want decimals on your report (or in your accounting system for that matter).
Actually I do want decimals in my accounting system, up to the last cent :-) And in some cases like interest/coupon accrual rounding is only at the end of the accrual period


int will always truncate downwards, when argument is float:

Quote:For floating point numbers, this truncates towards zero.

>>> int(5.99)
5
In your example with 5.50 + 0.50 it was the same - truncated toward 6
>>> d = 5.50 + 0.50
>>> d
6.0
>>> int(d)
6
(Apr-11-2020, 08:41 AM)DPaul Wrote: "random" so to speak.
Nothing random here

When working with money, better work with decimal.Decimal to avoid floating-point arithmetic surprises.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
rounding question - by DPaul - Apr-11-2020, 07:04 AM
RE: rounding question - by buran - Apr-11-2020, 07:13 AM
RE: rounding question - by bowlofred - Apr-11-2020, 07:23 AM
RE: rounding question - by DPaul - Apr-11-2020, 08:41 AM
RE: rounding question - by bowlofred - Apr-11-2020, 04:25 PM
RE: rounding question - by buran - Apr-11-2020, 08:58 AM
RE: rounding question - by ibreeden - Apr-11-2020, 08:59 AM
RE: rounding question - by DPaul - Apr-11-2020, 09:42 AM
RE: rounding question - by buran - Apr-11-2020, 09:56 AM
RE: rounding question - by DPaul - Apr-11-2020, 10:00 AM
RE: rounding question - by buran - Apr-11-2020, 10:05 AM
RE: rounding question - by TomToad - Apr-11-2020, 11:09 AM
RE: rounding question - by ibreeden - Apr-12-2020, 07:52 AM
RE: rounding question - by bowlofred - Apr-12-2020, 08:46 AM
RE: rounding question - by DPaul - Apr-12-2020, 10:59 AM
RE: rounding question - by TomToad - Apr-12-2020, 11:00 AM
RE: rounding question - by DPaul - Apr-12-2020, 02:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  need help rounding joseph202020 7 1,414 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  from numpy array to csv - rounding SchroedingersLion 6 2,318 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  Random data generation sum to 1 by rounding juniorcoder 9 3,585 Oct-20-2021, 03:36 PM
Last Post: deanhystad
  Rounding issue kmll 1 1,461 Oct-08-2021, 10:35 AM
Last Post: Yoriz
  Not rounding to desired decimal places? pprod 2 2,620 Mar-05-2021, 11:11 AM
Last Post: pprod
  Decimal Rounding error project_science 4 2,826 Jan-06-2021, 03:14 PM
Last Post: project_science
  rounding and floats Than999 2 3,174 Oct-26-2020, 09:36 PM
Last Post: deanhystad
  Rounding to the nearest eight wallgraffiti 2 2,144 Jul-15-2020, 06:05 PM
Last Post: wallgraffiti
  price + tax rounding mlieqo 11 6,596 Sep-21-2019, 04:53 PM
Last Post: mlieqo
  rounding floats to a number of bits Skaperen 2 2,355 Sep-13-2019, 04:37 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020