Link to home
Start Free TrialLog in
Avatar of DerekWatling
DerekWatlingFlag for South Africa

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("Bath"), "0.#")
but this still displays 1.0 as 1.0
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

dim str as string = CMAReader("Bath")

cmareader.LastIndexOf("</")
if string.Substring ( str , str.LastIndexOf(".") +1 , lstr.Length - str.LastIndexOf) = 0 then

 String.Format(CMAReader("Bath"), "0.#")
else
 String.Format(CMAReader("Bath"), "0#")
end if
ASKER CERTIFIED SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DerekWatling

ASKER

Thanks for some direction on this. After looking at your suggestion and playing a bit I have used
CMAReader("Bath").TrimEnd("0").TrimEnd(".")