Display decimal places only if needed...

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

So I have a web form that accepts temperature readings...and sometimes
the reading is a round number (ex. 74), and other times its not (ex.
58.3). I have the database setup to accept numeric(4,1), which shows
74.0 and 58.3 great, but I'd really like to only show the decimal
place if it's not zero...is this possible? I've googled for this for
awhile now and can't seem to find an answer...thanks in advance.

-Sean
 
Sean said:
So I have a web form that accepts temperature readings...and sometimes
the reading is a round number (ex. 74), and other times its not (ex.
58.3). I have the database setup to accept numeric(4,1), which shows
74.0 and 58.3 great, but I'd really like to only show the decimal
place if it's not zero...is this possible? I've googled for this for
awhile now and can't seem to find an answer...thanks in advance.

-Sean

How are you reading the values from the database? What data type do you
convert the values to?

Normally when converting a floating point value to a string, when the
decimal part is zero it's not included. How do you convert the value to
a string for displaying?
 
So I have a web form that accepts temperature readings...and sometimes
the reading is a round number (ex. 74), and other times its not (ex.
58.3). I have the database setup to accept numeric(4,1), which shows
74.0 and 58.3 great, but I'd really like to only show the decimal
place if it's not zero...is this possible? I've googled for this for
awhile now and can't seem to find an answer...thanks in advance.

-Sean

How about this?

http://msdn2.microsoft.com/en-us/library/0c899ak8(VS.71).aspx

static void Main()
{
decimal a = 58.3M;
decimal b = 74.0M;
string sa = a.ToString(".#"); // sa is "58.3"
string sb = b.ToString(".#"); // sb is "74"
}

John
 
They're read with an ObjectDataSource into a FormView most of the
time. I'll play around with converting them to strings to see what
kind of results I get.

-Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top