how can i make a change calculator?
for exmaple i want to buy an item thet cost 5.89$ and in canada no more 1 cents so how can round the number to 5.90?

Recommended Answers

All 3 Replies

This is how I tested for rounding to nearest five cents in https://www.pythonanywhere.com/try-ipython/ (useful as I have not Python and no Admin rights in work):

In [15]: granularity = .05
In [16]: #every five cents
In [17]: round(v/granularity) * granularity
Out[17]: 5.95
In [18]: round(8.91/granularity) * granularity
Out[18]: 8.9
In [19]: round(8.92/granularity) * granularity
Out[19]: 8.9
In [20]: round(8.93/granularity) * granularity
Out[20]: 8.950000000000001
In [21]: round(8.94/granularity) * granularity
Out[21]: 8.950000000000001
In [22]: round(8.95/granularity) * granularity
Out[22]: 8.950000000000001
In [23]: round(8.96/granularity) * granularity
Out[23]: 8.950000000000001
In [24]: round(8.97/granularity) * granularity
Out[24]: 8.950000000000001
In [25]: round(8.98/granularity) * granularity
Out[25]: 9.0
In [26]: round(8.99/granularity) * granularity
Out[26]: 9.0

the point that i dont know the number that i need to round it will be calculated from paid and cost . it will be the change that use need to get

ohhhhh i see. thank you its working ;DDDDD

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.