13,297,048 members (54,125 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"));```

Reply if this solves your problem. :)
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 phil.o 100 OriginalGriff 98 Richard MacCutchan 95 Jochen Arndt 75 ppolymorphe 75
 OriginalGriff 2,214 Jochen Arndt 1,255 Richard MacCutchan 1,140 ppolymorphe 962 CPallini 925

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 26 Dec 2012