Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Formatting Numbers with Decimal Places

Is it possible to format numbers that are displayed in a text box in such a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Formatting Numbers with Decimal Places

s = Format (value here, "0.##")
if right(s,1) = "." then
s = Replace(s,".","")
end if

--
Regards,
Tom Ogilvy



"James" wrote:

Is it possible to format numbers that are displayed in a text box in such a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formatting Numbers with Decimal Places

Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?


James wrote:

Is it possible to format numbers that are displayed in a text box in such a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formatting Numbers with Decimal Places

What do you want to see with a value like 12.0000000000001?

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote in message
...
Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?


James wrote:

Is it possible to format numbers that are displayed in a text box in such
a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when
whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formatting Numbers with Decimal Places

Me?

I don't care.

But sometimes people want to see different things if the value isn't really a
counting number.

Or am I missing the real point?

Tom Ogilvy wrote:

What do you want to see with a value like 12.0000000000001?

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?


James wrote:

Is it possible to format numbers that are displayed in a text box in such
a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when
whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Formatting Numbers with Decimal Places

Like your post,
Just added info for the OP.

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote:

Me?

I don't care.

But sometimes people want to see different things if the value isn't really a
counting number.

Or am I missing the real point?

Tom Ogilvy wrote:

What do you want to see with a value like 12.0000000000001?

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?


James wrote:

Is it possible to format numbers that are displayed in a text box in such
a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when
whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James

--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formatting Numbers with Decimal Places

Ahhhh.



Tom Ogilvy wrote:

Like your post,
Just added info for the OP.

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote:

Me?

I don't care.

But sometimes people want to see different things if the value isn't really a
counting number.

Or am I missing the real point?

Tom Ogilvy wrote:

What do you want to see with a value like 12.0000000000001?

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?


James wrote:

Is it possible to format numbers that are displayed in a text box in such
a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when
whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do my numbers keep going down decimal places? Excell2002ishard Setting up and Configuration of Excel 2 March 27th 08 09:36 PM
Why do my numbers keep going down decimal places? Excell2002ishard Setting up and Configuration of Excel 2 March 27th 08 08:09 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
formatting decimal places for complex numbers beav Excel Programming 0 May 20th 06 10:36 AM
Trim numbers to x decimal places Andrea[_8_] Excel Programming 7 February 26th 04 03:04 PM


All times are GMT +1. The time now is 07:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"