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?
There are a lot of possibilities:
see:
- 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
- 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 - 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 ;-)
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?
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,