473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

money round

hello,
a little problem :
i must do a round number from : 1.125 $ (1 dollar 125)
but Math.Round(1.125, 2) = 1.12 and not 1.13 ...
how do ?

actually i use : Math.Round(1.125+0.0000001, 2) but its not really clean...

thanks
Mar 27 '08 #1
2 1651
On Thu, 27 Mar 2008 08:37:46 -0700, Steph <st***@pipoland.comwrote:
hello,
a little problem :
i must do a round number from : 1.125 $ (1 dollar 125)
but Math.Round(1.125, 2) = 1.12 and not 1.13 ...
how do ?
Just use one of the overloads for Math.Round() that allows you to specify
the MidpointRounding mode.

Pete
Mar 27 '08 #2
Jon Skeet [C# MVP] wrote:
Steph <st***@pipoland.comwrote:
>a little problem :
i must do a round number from : 1.125 $ (1 dollar 125)
but Math.Round(1.125, 2) = 1.12 and not 1.13 ...
how do ?

actually i use : Math.Round(1.125+0.0000001, 2) but its not really clean...

Use an overload of Math.Round which takes a MidpointRounding parameter.
Oh, and stop using double to represent money - use decimal instead.
thanks
Mar 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stefan Richter | last post by:
Hi, I am looking for a good function to check if a entered value is a money value - meaning it's a decimal with no more then 2 digits after the point. Thanks, Stefan
24
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
2
by: Matias Silva | last post by:
Can anybody tell me why I am getting rounding errors using the ROUND function. 3.7125 rounds to 3.70 when I use the following: TRUNCATE(ROUND(units_pay_amount * fees_amount, 2),2))) The correct...
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
7
by: kkmigas | last post by:
Can some one explain if this can be fixed using php.ini settings ? echo "round 20.545 -".round(20.545,2)."<br>"; echo "round 20.555 -".round(20.555,2)."<br>"; echo "number_format 20.545...
15
by: soni2926 | last post by:
Hi, I have the following: float.Parse(myproduct.Price.Value.ToString()); myproduct.Price.Value.ToString() returns $24.00 (with the $) Is there anyway to do the above cast, I know the...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
9
by: bb | last post by:
Hi, Are there any open source data types ( c++ classes ) for Money and/or Price that I can inherit and customize for my use instead of writing from the scratch? Any help would be much...
7
KoreyAusTex
by: KoreyAusTex | last post by:
I am having a very hard time making this program work right, I am sort of lost and I was wondering if I might get some advice. This is what I have so far but I have a rounding error when I use the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.