Textfield with "money" value from DB, shows 4 decimals. How to remove them?

I have a textfield which is bound to a database field of type Money. The problem is that it shows 4 decimal places. I don't want to show any decimals, and preferably round it instead of trimming.

I'm fairly new to windows forms - are there any properties that lets me control this?

Or do i really have to manually program every field to round the value, and trim the decimals?

I find it pretty silly that it's displaying 4 decimals by default - even when it's 1,0000... 2 would be "ok", but 4... What currencies have 4?

[566 byte] By [James_Steven] at [2007-12-25]
# 1
you can use the Math.Round function/method to round your value to the specified number of decimals if this helps?
ahmedilyas at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

There are a lot of possibilities:

see:

  1. Console.Write("{0:F0}", 25.9999); // Will Print 4 only and automatically round correctly will print 26 and U know the reason why should it do so
  2. double d = 12.9999;
    long l = (long) d; // Will automatically Trim the desimel points but you loose value and get 12 only loss of 0.9999
  3. double d = 12.9999;
    d = Math.Round(d); // Also working fine

Now choose 1 that better suites your need, String.Format() is better in you case because no explicit casting is needed at your end.

Cheers ;-)

RizwanSharp at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

I know how to round a string/int, but are there really now way to restrict this in the textbox it self?

So i must create an OnChange event, and do the rounding there?

James_Steven at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

First, you need to pass the values from a filter which may trim the values as per your need.

Second way is that do it with the help of SQL queries you are using to load data on your controls so that they queries shape the values using SQL functions and then load the shapped data in the controls.

Best Regards,

RizwanSharp at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
I found out that i could adjust control formatting in "Databindings -> Advanced".
James_Steven at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...