?
Solved

Formatting floating point numbers

Posted on 2007-10-15
3
Medium Priority
?
1,404 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:DerekWatling
  • 2
3 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 20076906
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
0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 150 total points
ID: 20076910
Try this one instead of the previous...

dim str as string = CMAReader("Bath")

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
0
 

Author Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question