473,549 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to prevent roundiing in NumericUpDown

Avi
Hello All,
I am using NumericUpDown control. I have set Decimal places property to

3.
Problem is that when I programatically assign it a value which has 4
digits after decimal point ,
it rounds the value to 3 digits. E.g. 0.0695 --> 0.070
How can I prevent this rounding? I want the value to remain like 0.0695

--> 0.069.
Thanks

Jan 4 '06 #1
4 3669
On 4 Jan 2006 03:37:29 -0800, "Avi" <av********@gma il.com> wrote:
Hello All,
I am using NumericUpDown control. I have set Decimal places property to

3.
Problem is that when I programatically assign it a value which has 4
digits after decimal point ,
it rounds the value to 3 digits. E.g. 0.0695 --> 0.070
How can I prevent this rounding? I want the value to remain like 0.0695

--> 0.069.
Thanks


Set decimal place property to 4?

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Jan 5 '06 #2
Avi
Sorry, I will correct myself.
"I want the value to remain like 0.069", that is 3 decimal places only.

Thanks

Jan 5 '06 #3
Avi,
Problem is that when I programatically assign it a value which has 4
digits after decimal point, it rounds the value to 3 digits.
How can I prevent this rounding?


Since you are programmaticall y setting the new value for the NumericUpDown
control, you are free to round/truncate the value *before* you assign it to
the Value property of the NumericUpDown control.

That is, in your code you are probably doing something like this:

---------------
decimal myValue = 0.0695m; // some calculation here
numericUpDown1. Value = myValue;
---------------

Now, instead of directly assigning the result of your calculation to the
Value property and let the control round the number for you, you would
simply round the result to your liking, in this case round down instead of
up.

To do so, you could use simple code like this:

---------------
decimal myValue = 0.0695m;
decimal myRoundedValue = System.Math.Tru ncate(myValue * 1000) / 1000;
numericUpDown1. Value = myRoundedValue;
---------------

Of course, this code might not be exactly what you want (as you didn't
specify exactly how you want to round), but something very similar should be
what you are after.

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethi s.dystopia.fi
http://www.saunalahti.fi/janij/
Jan 5 '06 #4
Avi
That's exactly what a want.

Thanks a lot.

Jan 6 '06 #5

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

Similar topics

21
9845
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
10
7123
by: Bonj | last post by:
I'm using a number of NumericUpDown controls on my form, which controls printer settings such as number of pages. However I want to override one of the default behaviours of the control, namely when it is tabbed into (selected), I want the number that is displayed in it to become selected, so the user can just type straight over it. For this...
0
1420
by: Koert | last post by:
Hi In the NumericUpDown control I have to detect that Tab was pressed so I have inherited the NumericUpDown and overroden the PreProcessMessage function. In the DateTimePicker (for example) this works fine but not in the NumericUpDown. It seams that the debugger does not access the PreProcessMessage function. Is this a bug in the NumericUpDown...
1
1806
by: Jay Banks | last post by:
I know this was recently posted in reference to a textbox, but I'm having a similar problem, and can't keep it from beeping. I'm using a NumericUpDown control instead of a textbox. I've tried this code in the KeyPress and the KeyDown events. None of the below code prevents the beep. If e.KeyCode = Keys.Enter Then e.Handled = True ......
3
30093
by: abc my vclass | last post by:
My win-form have many numericupdown controls to applied. But numericupdown control don't like textbox, text box control can automatic selected text when got focus. Is there any method can let me set all numericupdown autoselect text when gotfocus?
4
4676
by: illegal.prime | last post by:
Hey all, I have a NumericUpDown control on a Panel or potentially a Form that have AutoScroll enabled. When the NumericUpDown is active I would like the Form/Panel/whatever not to scroll when I scroll the value in the NumericUpDown. I can add an additional handler to the MouseWheel event on the NumericUpDown, but how do I stop the...
5
2168
by: Len Weltman | last post by:
I am trying to pass a NumericUpDown object into a class method using Visual Studio 2005, but the control type is not found in Intellisense and the type declaration is flagged as an error. Here is a code sample (which doesn't work): *** Begin code ***
2
1321
by: MH-2004 | last post by:
Hi All, I have a MDI form application. In a child form I placed a bunch of NumericUpDown controls. The problem happens when I use the mouse scroll button, the value in the NumericUpdown has changed and the form also scrolls out of control. How do I make the detatch those two types of controls so that only one gets the mouse scrolling event....
2
2382
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello experts, I posted a disturbing question in here: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.languages.csharp&mid=dedc665f-91c0-4fa4-a103-a98a6808759c But no one have answered it. Is not clear? or maybe it a Framework bug? Please help.
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.