From: mp on
Trying to use the format method in vb.net
to oconvert a double to string of 4 places

I tried:
Format(CStr(dHeightOfStone), "x.xxxx")

and:

Format(CStr(dHeightOfStone), "#.####")

It returns "x.xxxx" or "#.####" instead of "36.1875" (or whatever number was
input)

any tips?

thanks mark




From: Armin Zingler on
Am 17.03.2010 23:56, schrieb mp:
> Trying to use the format method in vb.net
> to oconvert a double to string of 4 places
>
> I tried:
> Format(CStr(dHeightOfStone), "x.xxxx")
>
> and:
>
> Format(CStr(dHeightOfStone), "#.####")
>
> It returns "x.xxxx" or "#.####" instead of "36.1875" (or whatever number was
> input)
>
> any tips?

These format strings are for formatting numbers. You are trying
to format strings because, before, you've converted the numbers
to strings using the CStr function. Try this instead:

dHeightOfStone.ToString("#.####")


--
Armin
From: Family Tree Mike on
On 3/17/2010 6:56 PM, mp wrote:
> Trying to use the format method in vb.net
> to oconvert a double to string of 4 places
>
> I tried:
> Format(CStr(dHeightOfStone), "x.xxxx")
>
> and:
>
> Format(CStr(dHeightOfStone), "#.####")
>
> It returns "x.xxxx" or "#.####" instead of "36.1875" (or whatever number was
> input)
>
> any tips?
>
> thanks mark
>
>
>
>

I believe you want to use Format(dHeightOfStone, "#.####").

Frankly, I prefer dHeightOfStone.ToString("f4"), but that's just my style...

--
Mike
From: mp on
ok, even though the help files show the order i first tried,
> Format(CStr(dHeightOfStone), "#.####")
i tried the opposite order
> Format( "#.####", CStr(dHeightOfStone))
now instead of getting "#.####" returned, i get
4.62500000000364

so it's still not formatting
what am i missing?

as an alternative i tried using round
Dim sWidthLiner As String =
CStr(Decimal.Round(Cdec(dLengthOfMoldSidesLiner), 4))

but it seems a long way around to just get a double rounded to x places and
converted to string

thanks
mark


"mp" <nospam(a)thanks.com> wrote in message
news:Oh0AcUixKHA.2644(a)TK2MSFTNGP04.phx.gbl...
> Trying to use the format method in vb.net
> to oconvert a double to string of 4 places
>
> I tried:
> Format(CStr(dHeightOfStone), "x.xxxx")
>
> and:
>
> Format(CStr(dHeightOfStone), "#.####")
>
> It returns "x.xxxx" or "#.####" instead of "36.1875" (or whatever number
> was input)
>
> any tips?
>
> thanks mark
>
>
>
>


From: mp on
Thanks Mike and Armin,

"Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
news:uVVEMcixKHA.5036(a)TK2MSFTNGP02.phx.gbl...
> On 3/17/2010 6:56 PM, mp wrote:
>> Trying to use the format method in vb.net
>> to oconvert a double to string of 4 places
>>
>> I tried:
>> Format(CStr(dHeightOfStone), "x.xxxx")
>>
>> and:
>>
>> Format(CStr(dHeightOfStone), "#.####")
>>
>> It returns "x.xxxx" or "#.####" instead of "36.1875" (or whatever number
>> was
>> input)
>>
>> any tips?
>>
>> thanks mark
>>
>>
>>
>>
>
> I believe you want to use Format(dHeightOfStone, "#.####").
>
> Frankly, I prefer dHeightOfStone.ToString("f4"), but that's just my
> style...
>
> --
> Mike