Convert String value to float or double in C#

Last Reply on Dec 14, 2016 03:38 AM By dharmendr

Posted on Dec 14, 2016 03:36 AM

hi

There is Some Value in database as 20.00(nvarchar)

When i get this value in c# Code  it comes in string "20.05" up to here ok.when i try to convert this value to float it Shows 20.0

How i get it actuaal what is in database like 20.05

 

You are viewing reply posted by: dharmendr on Dec 14, 2016 03:38 AM.
Posted on Dec 14, 2016 03:38 AM Modified on on Dec 14, 2016 03:38 AM

Hi droiddeve,

Refer the below code.

string a = "20.05";
float b = float.Parse(a, System.Globalization.CultureInfo.InvariantCulture.NumberFormat); // 20.05
OR
double c = Convert.ToDouble(a); // 20.05