Re: Cannot get format to work

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"nod" <nod@xxxxxxxxxx> wrote in message
news:nsr9i3p6jboaeot792vuflf3nk302i6tgg@xxxxxxxxxx
I have a variable called 'cost'
It is a number rounded up to 2 decimal places.

I need to display it in a Rich Text box using a comma separator for
thousands and always displaying two digits to the right of the decimal
point.
To do so I have tried numerous permutations declaring cost both as
Currency and Double along with:
FormatCurrency( cost,2)
Format( cost,"#,##0.00")
Format|(cost,"Fixed")
Format|(cost,"Standard")

Nothing works for me.
I would be grateful ifsomeone could tell me what I am doing wrong.



You should really explain "Nothing works". What result(s) ARE you getting?
Is it just the format that's not right or is the value off by a small amount
(probably only by .01)?

FormatCurrency is locale-aware. So, if your regional settings are set to
use something other than a comma for the thousands separator, that's what
you'll get. The same goes for the currency symbol and the decimal symbol.
But, using Format and a user-defined format string (your second example)
should be using a comma for the thousands separator regardless of regional
settings. Perhaps that will shed some light if the problem is just the
formatting.

If the value itself is off, then it might be due to Format (or
FormatCurrency) itself doing some rounding. Pay close attention to the
ACTUAL value that you're formatting because it might have 3 or more decimal
places (and since you're formatting for 2 decimal places, it could be
getting rounded again).

If you still can't get this sorted out, post back but include the ACTUAL AND
COMPLETE value you're attempting to format.

--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • Re: Concatenated numerical literals
    ... commas and currency symbol and hacked it a little to make ... import types, string ... This function will take the number passed to it and format it as US ... comma separators and two decimal places ...
    (comp.lang.python)
  • Re: Hidden VBA Code
    ... This will display the code module for the item clicked. ... There was a Comma button on my Add-Ins menu, and it would display the "Hi" ... spreadsheet out for my contact to work on it. ...
    (microsoft.public.excel.programming)
  • Re: Saving Form Data Only as Plain Text File for Importing into Database
    ... The data is saved in comma ... separated value format so that it can be imported into a database. ... Doug Robbins - Word MVP ...
    (microsoft.public.word.vba.userforms)
  • Re: Format Number with thousands comma but no decimal places
    ... Ntl News Group wrote: ... The problems is that this displays 1234 and I want it to display 1,234 ... using a comma for the thousands and no decimal places. ... can also explicitly define the format you want like this... ...
    (comp.databases.ms-access)
  • Re: Hidden VBA Code
    ... If you open the VB editor and look in the Project window, ... There was a Comma button on my Add-Ins menu, and it would display the "Hi" ... entered data on a second tab (HOME2). ...
    (microsoft.public.excel.programming)