Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
 
please help.
Posted 25-Dec-12 22:11pm
Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
Comments
__TR__ at 26-Dec-12 6:17am
   
My 5.
Sergey Alexandrovich Kryukov at 26-Dec-12 12:24pm
   
Thank you.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

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. Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

this way also, this problem can be solved...
string s = (Convert.ToDouble(textbox1.Text) / 100).ToString("0.00");
Happy Coding!
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100