algorithm - Round off Decimals(Price) to .50 or whole numbers. C# winforms -


hi guys item prices in system generated system , round up.

like this: 1.01 1.49 1.50 , 1.51 1.99 2.00

examples: 5.56 -> 6.00 , 5.32 -> 5.50

how can achieve this? thank you.

rounding done using math.ceiling method.

applying method directly round nearest dollar. trick rounding nearest 50 cents double price, take ceiling, , returning half of result:

decimal roundedtofiftycents = math.ceiling(2 * originalprice) / 2; 

demo.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -