Re: Formatting numbers
From: Top Spin (ToppSpin_at_hotmail.com)
Date: 12/02/04
- Next message: Bob Butler: "Re: Inline assembly [MULTIPOST]"
- Previous message: Ken Halter: "Re: Inline assembly [MULTIPOST]"
- In reply to: Rick Rothstein: "Re: Formatting numbers"
- Next in thread: Bob Butler: "Re: Formatting numbers"
- Reply: Bob Butler: "Re: Formatting numbers"
- Reply: Rick Rothstein: "Re: Formatting numbers"
- Messages sorted by: [ date ] [ thread ]
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)
- Next message: Bob Butler: "Re: Inline assembly [MULTIPOST]"
- Previous message: Ken Halter: "Re: Inline assembly [MULTIPOST]"
- In reply to: Rick Rothstein: "Re: Formatting numbers"
- Next in thread: Bob Butler: "Re: Formatting numbers"
- Reply: Bob Butler: "Re: Formatting numbers"
- Reply: Rick Rothstein: "Re: Formatting numbers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|