Convert String value to float or double in C#

on Dec 14, 2016 03:36 AM


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


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Dec 14, 2016 03:38 AM
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
double c = Convert.ToDouble(a); // 20.05