Re: Formatting numbers

From: Top Spin (ToppSpin_at_hotmail.com)
Date: 12/02/04


Date: Thu, 02 Dec 2004 08:40:43 -0800

On Thu, 2 Dec 2004 01:45:23 -0500, "Rick Rothstein"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote:

>> >What's the easiest way to format a number so that the result is n
>> >characters wide, has m decimal places displayed (with rounding), and
>> >has a comma every 3 places on the left?
>> >
>> >The FormatNumber$ function comes close. It allows me to specify the
>> >number of decimal places and control the thousands delimiters, but I
>> >have no control over the total field width. If only I could add one
>> >parameter:
>> >
>> > FormatNumber$(nData,n,m)
>> >
>> >The Format$ function does it all, but I have to generate a format
>> >mask. I'd like simple numeric parameters n and m.
>>
>> Ooopps. My mistake. Format$ does not do it all unless I want leading
>> zeroes. I forgot that
>>
>> Format$(123,"#####")
>>
>> returns a string of length 3, not 5.
>
>Does this function do what you want?
>
>Function FieldFormat(Value As Variant, _
> DecimalPlaces As Long, _
> FieldSize As Long) As String
> Dim DecimalPoint As String
> If DecimalPlaces > 0 Then DecimalPoint = "."
> FieldFormat = Format$(Format$(Value, "#,###" & _
> DecimalPoint & _
> String$(DecimalPlaces, "#")), _
> String$(FieldSize, "@"))
>End Function

This mostly works. One problem is:

?fieldformat(123,2,6)
  123.

But I wasn't aware of the "@" character. I think I can use that to
make exactly what I want.

Thanks

--
Running MS VB 6.0 Pro (SP5)
PC: HP Omnibook 6000
OS: Win 2K SP-4 (5.00.2195)
Email: Usenet-20031220 at spamex.com
(11/03/04)


Relevant Pages

  • /proc/<pid>/maps syntax
    ... Encourage better documentation of such formats ... We ended up with an inferior format in the long run. ... address and offset fields may or may not have leading zeroes, ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Number with leading zeros
    ... as there is no information on what the number of zeroes should be. ... >>Format is only part of presentation, ... >>Bob Phillips ... >>> I am copying numbers with leading zeros into excel. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Unexpected Result with "If" Logic/Conditional Statement
    ... with the "Special" Zip format, but I need to account for leading zeroes, ... check the actual outcome with the expected outcome. ... Computer Solutions ...
    (microsoft.public.excel.misc)
  • Re: How to Write Text data in Binary Format
    ... When a program opens a file, it interprets those ones and zeroes, and does with them whatever the program knows how to do. ... The BinaryWriter is dumping into the file the same sequence of ones and zeroes that the String had in memory. ... format that is not human understandable.....please note i dont want to ... no format is directly understandable to most humans. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: formula application to cells
    ... Even though these characters are probably used as "parts numbers", ... very easily just format the column into a number format, ... And in the "Type" box enter the ten zeroes, ... I copied the formula to bottom of each column, ...
    (microsoft.public.excel.worksheet.functions)