Last post Jul 26, 2017 04:54 AM by pelums123
Member
127 Points
79 Posts
Jul 19, 2017 08:19 PM|ramakrishnan27|LINK
hi, When I am trying to convert a decimal value to string last decimal value is missing.
This is the decimal value I am using "1630.0" when I am converting to string I am getting as "1630" ( .0 is missing )
my code
double after1 = 1630.0; string[] _newvalu = after1.ToString(); // 1630 _value =_newvalu;
All-Star
48570 Points
18082 Posts
Jul 19, 2017 08:44 PM|PatriceSc|LINK
Hi,
Numeric values never cares about non significant digits and using 0001630.000 in your source code would still assign the SAME value to after1.
You can use after1.ToString("n1"); to force showing 1 digit when converting this numeric value to a string See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings for details.
Star
8670 Points
2882 Posts
Jul 20, 2017 03:20 AM|Cathy Zou|LINK
Hi Ramakrishna,
You also could use string.Format method instead:
double after1 = 1630.0; string _newvalu = string.Format("{0:0.0}", after1); Response.Write(_newvalu);
Best regards
Cathy
1 Points
6 Posts
Jul 26, 2017 04:54 AM|pelums123|LINK
Hello try using this code.
float after1 = 1630.0f;
double value = Math.Round(after1, 2);
label1.Text = string.Format("{0:0.00}", value);
Member
127 Points
79 Posts
Decimal value to string missing last two decimal value..
Jul 19, 2017 08:19 PM|ramakrishnan27|LINK
hi, When I am trying to convert a decimal value to string last decimal value is missing.
This is the decimal value I am using "1630.0" when I am converting to string I am getting as "1630" ( .0 is missing )
my code
double after1 = 1630.0;
string[] _newvalu = after1.ToString(); // 1630
_value =_newvalu;
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
All-Star
48570 Points
18082 Posts
Re: Decimal value to string missing last two decimal value..
Jul 19, 2017 08:44 PM|PatriceSc|LINK
Hi,
Numeric values never cares about non significant digits and using 0001630.000 in your source code would still assign the SAME value to after1.
You can use after1.ToString("n1"); to force showing 1 digit when converting this numeric value to a string See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings for details.
Star
8670 Points
2882 Posts
Re: Decimal value to string missing last two decimal value..
Jul 20, 2017 03:20 AM|Cathy Zou|LINK
Hi Ramakrishna,
You also could use string.Format method instead:
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
6 Posts
Re: Decimal value to string missing last two decimal value..
Jul 26, 2017 04:54 AM|pelums123|LINK
Hello try using this code.
float after1 = 1630.0f;
double value = Math.Round(after1, 2);
label1.Text = string.Format("{0:0.00}", value);