redho home | products | services

Programming Forums


Community for Java, PHP, Perl C, ASP and Python programmers
Sunday 09 December 2018 21:17

Ask your IT question here

Having trouble with rounding numbers



 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Programming Forums -> Python programming forum
View previous topic :: View next topic  
Author Message
python chemist
Guest Programmer




I would like to round numbers to certain values that are not always just to the nearest integer or multiple of 10. For instance I would like to be able to round the number 1245 to the nearest 50 (so 1250), the nearest 100 (so 1200), the nearest 1000 (so 1000), or the nearest other number. I've tried using the round(1245, -1) values; and i know this will return 1250, but I cannot figure out how to round to other values.

Any help would be much appreciated. Thanks.

Reply with quote
 
Madwolf
Site Admin


Joined: 22 Dec 2004
Posts: 77
Hello python chemist. Smile
Welcome to Programming forums! Smile
Did you try
round(1245,-2) will result in 1200
round(1245,-3) will result in 1000

Cheers Wink

Reply with quote
 
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Programming Forums -> Python programming forum


Dubai Forums - Expat Help | Vegan Forum | Java Programming | 3d Design Resources | 3d Forum | 3D Jobs | 3D Textures | Paris Forum | Europe Forum
Dubai Classifieds | Dubai Property | Jobs in Dubai | Free London Classifieds | Jobs in London UK

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

© 2018 RedHo