I don't mean precision as in how many numbers are displayed after the decimal. I mean precision as in the decimal I am trying to use in this pictograph function keeps coming up one tenth shy of what it should be. I have tried using multiple different strategies including importing the decimal module. Here is the function I am trying to use.
values = [('tens', 10), ('fives', 5), ('ones', 1), ('tenths', 0.1)]
def get_digits(num):
num = int(num * 10)
num = float(num) / 10
output_dict = {}
for place, value in values:
output_dict[place] = int(num // value)
num = num % value
return output_dict
using get_digits(277.9)
, yields {'tens': 27, 'ones': 2, 'tenths': 8, 'fives': 1}
I need for it to say {'tens': 27, 'ones': 2, 'tenths': 9, 'fives': 1}
Fixing it by adding 1 to the tenths after the dictionary is populated does not work, because not every decimal comes out imprecisely.
get_digits(277.6)
returns {'fives': 1, 'tenths': 6, 'tens': 27, 'ones': 2}
I've been scouring the forums for an answer, but nothing quite gets it. Any assistance would be greatly appreciated.