DerekWatling
asked on
Formatting floating point numbers
In VB.NET how does one format a floating point number so the decimal only displays if it exists?
I am pulling data from a MySQL database where one of the columns is FLOAT(4,1) UNSIGNED. When I display the data on my ASP.NET page I only want the decimal to show if it is significant, ie.
1.0 should display as 1
1.5 should display as 1.5
At the moment I have
String.Format(CMAReader("B ath"), "0.#")
but this still displays 1.0 as 1.0
I am pulling data from a MySQL database where one of the columns is FLOAT(4,1) UNSIGNED. When I display the data on my ASP.NET page I only want the decimal to show if it is significant, ie.
1.0 should display as 1
1.5 should display as 1.5
At the moment I have
String.Format(CMAReader("B
but this still displays 1.0 as 1.0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for some direction on this. After looking at your suggestion and playing a bit I have used
CMAReader("Bath").TrimEnd( "0").TrimE nd(".")
CMAReader("Bath").TrimEnd(
cmareader.LastIndexOf("</"
if string.Substring ( str , str.LastIndexOf(".") +1 , lstr.Length - str.LastIndexOf) = 0 then
String.Format(CMAReader("B
else
String.Format(CMAReader("B
end if