12,633,764 members (31,259 online)
Rate this:
See more:
I want to convert the text box value to decimal(3,2) like 3.22 ,4.33, etc
i tried to divide the text box value by 100 but it is converting the decimal values to 0 like for 123 it is storing 1.00 but i want 1.23 to be stored in db.

Posted 25-Dec-12 22:11pm

Rate this:

## Solution 2

There is no such thing as `decimal(3,2)` or something like that. It looks like you mix up different things: data, numeric types, and string representation of numeric data. You need to work with data, not strings. And don't put strings in a database where you can use numeric types. If you do it, you need to fix the database schema.

You problem is merely a problem of formally of decimal data when you present it somewhere on the screen. Please see:
http://msdn.microsoft.com/en-us/library/364x0z75%28v=vs.80%29.aspx[^].

For string formatting of decimal values, please see:
http://msdn.microsoft.com/en-us/library/system.decimal.tostring.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

—SA
__TR__ 26-Dec-12 6:17am

My 5.
Sergey Alexandrovich Kryukov 26-Dec-12 12:24pm

Thank you.
—SA
Rate this:

## Solution 3

If you divide the textbox value by 100 123 will be shown as 1.00 because of integer division. To solve this you should follow the below code:-
```
double val = 537/100f; // f tells compiler to perform float division
Console.WriteLine(val.ToString("#0.00"));
```

Rate this:

## Solution 4

this way also, this problem can be solved...
`string s = (Convert.ToDouble(textbox1.Text) / 100).ToString("0.00");`

Happy Coding!
:)
Rate this:

## Solution 1

Decimal (3,2) means total length is 3, out of which 2 are reserved for decimal. Then nothing will be before decimal.

Ex:- Decimal(12,8) means total length 12 out of which 8 before decimal and 4 after decimal.

So increase the length of your field in database
May it helps you

Top Experts
Last 24hrsThis month
 OriginalGriff 305 Peter Leow 195 CHill60 105 Jochen Arndt 80 F-ES Sitecore 80
 OriginalGriff 2,274 ppolymorphe 1,252 Peter Leow 999 John Simmons / outlaw programmer 715 CPallini 621