Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Format decimals in VBA function

I input dblTargetValue and dblLowScoreValue as Double into a VBA
function and show the output as a string, like this:

Dim strOutput as string
strOutput = CStr((dblTargetValue - dblLowScoreValue))

I want to round the output so that it doesn't show too many decimals,
like this:
* If dblTargetValue - dblLowScoreValue = 0 decimals, show 0 decimals
* If dblTargetValue - dblLowScoreValue = 1 decimals, show 1 decimal
* If dblTargetValue - dblLowScoreValue = 2 decimals, show 2 decimals
* If dblTargetValue - dblLowScoreValue = 3 decimals, show 3 decimals

I really need help with this immediately because I have a deadline to
keep so I'm very grateful for help!

Regards,

SE

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Format decimals in VBA function

Dim strOutput As String
strOutput = Application.Text(Round(dblTargetValue - dblLowScoreValue, 3),
"General")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ps.com...
I input dblTargetValue and dblLowScoreValue as Double into a VBA
function and show the output as a string, like this:

Dim strOutput as string
strOutput = CStr((dblTargetValue - dblLowScoreValue))

I want to round the output so that it doesn't show too many decimals,
like this:
* If dblTargetValue - dblLowScoreValue = 0 decimals, show 0 decimals
* If dblTargetValue - dblLowScoreValue = 1 decimals, show 1 decimal
* If dblTargetValue - dblLowScoreValue = 2 decimals, show 2 decimals
* If dblTargetValue - dblLowScoreValue = 3 decimals, show 3 decimals

I really need help with this immediately because I have a deadline to
keep so I'm very grateful for help!

Regards,

SE



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Format decimals in VBA function

Thank's a lot! It works great!

Regards,

S

Bob Phillips skrev:

Dim strOutput As String
strOutput = Application.Text(Round(dblTargetValue - dblLowScoreValue, 3),
"General")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ps.com...
I input dblTargetValue and dblLowScoreValue as Double into a VBA
function and show the output as a string, like this:

Dim strOutput as string
strOutput = CStr((dblTargetValue - dblLowScoreValue))

I want to round the output so that it doesn't show too many decimals,
like this:
* If dblTargetValue - dblLowScoreValue = 0 decimals, show 0 decimals
* If dblTargetValue - dblLowScoreValue = 1 decimals, show 1 decimal
* If dblTargetValue - dblLowScoreValue = 2 decimals, show 2 decimals
* If dblTargetValue - dblLowScoreValue = 3 decimals, show 3 decimals

I really need help with this immediately because I have a deadline to
keep so I'm very grateful for help!

Regards,

SE


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Format decimals in VBA function

Dim strOutput As String
strOutput = Format(dblTargetValue - dblLowScoreValue, "#,##0.###")

Would be another way.

for example:
? format(123.4,"#,##0.###")
123.4
? format(123.45,"#,##0.###")
123.45
? format(123.456,"#,##0.###")
123.456
? format(123.4563,"#,##0.###")
123.456
? format(123.4567,"#,##0.###")
123.457


--
Regards,
Tom Ogilvy


" wrote:

Thank's a lot! It works great!

Regards,

S

Bob Phillips skrev:

Dim strOutput As String
strOutput = Application.Text(Round(dblTargetValue - dblLowScoreValue, 3),
"General")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ps.com...
I input dblTargetValue and dblLowScoreValue as Double into a VBA
function and show the output as a string, like this:

Dim strOutput as string
strOutput = CStr((dblTargetValue - dblLowScoreValue))

I want to round the output so that it doesn't show too many decimals,
like this:
* If dblTargetValue - dblLowScoreValue = 0 decimals, show 0 decimals
* If dblTargetValue - dblLowScoreValue = 1 decimals, show 1 decimal
* If dblTargetValue - dblLowScoreValue = 2 decimals, show 2 decimals
* If dblTargetValue - dblLowScoreValue = 3 decimals, show 3 decimals

I really need help with this immediately because I have a deadline to
keep so I'm very grateful for help!

Regards,

SE



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
Format Decimals and Whole Numbers Lankchevy Excel Programming 3 December 16th 05 03:50 PM
Cell format decimals Ramthebuffs Excel Discussion (Misc queries) 4 November 1st 05 08:03 PM
how do I format decimals Bob Kilmer Excel Programming 0 September 3rd 04 12:37 AM
how do I format decimals Andoni[_34_] Excel Programming 0 September 3rd 04 12:36 AM
how do I format decimals Jim Thomlinson[_3_] Excel Programming 0 September 3rd 04 12:35 AM


All times are GMT +1. The time now is 04:18 PM.

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"