From: Sheldon on
Hello -

For some reason, I am unable to type 0.000 or 0.100 in code. Everytime I do
it, it's automatically stripped away to 0.0 or 0.1.

Is there a setting or something I need to change?
--
Sheldon
From: Armin Zingler on
Sheldon schrieb:
> Hello -
>
> For some reason, I am unable to type 0.000 or 0.100 in code. Everytime I do
> it, it's automatically stripped away to 0.0 or 0.1.
>
> Is there a setting or something I need to change?

0.1 is the same as 0.100

Numbers don't have leading or trailing decimal places. Only strings have.

--
Armin
From: Captain Jack on
"Sheldon" <Sheldon(a)discussions.microsoft.com> wrote in message
news:279AB541-AC27-48DB-A39D-615C41ED4D00(a)microsoft.com...
>
> For some reason, I am unable to type 0.000 or 0.100 in code. Everytime I
> do
> it, it's automatically stripped away to 0.0 or 0.1.
>
> Is there a setting or something I need to change?

The only way I know of is to turn off the formatting from the menu (Tools ->
Options, then Text Editor -> Basic -> VB Specific, then uncheck "Pretty
listing (reformatting of code)"). That's going to turn off a lot of other
formatting that you may want to keep, however.

If you just gotta have trailing zeros in your code (you don't need them,
they don't control precision or anything) and you don't care about
performance hits, you can enter your numbers as strings and tell the
compiler to convert them, like this:

Dim X As Double = CDbl("0.100")

or this:

Dim Result As Boolean = MyFunction(CDbl("0.000"), CDbl("0.100"))

Which is, of course, clunky as all get-out, but everything would line up
nicely. I've done that for little one-shot analysis programs where I wanted
to make sure my numbers were set up right, but I wouldn't do it in
production code.

--
Jack


From: Martin H. on
Hello Jack, hello Sheldon,


> Dim X As Double = CDbl("0.100")
> Dim Result As Boolean = MyFunction(CDbl("0.000"), CDbl("0.100"))

This is not a good method, because it will not work if the decimal
separator is not a period. On my system (German), the decimal separator
is a ",".

The following code

Dim dec As Decimal
dec = CDec("1.00")
MsgBox(dec.ToString())

does not show "1.00", but "100", because in Germany the period is used
only for separating thousands (on English system that would be ",").

The proper way to do it would be:

Dim dec1 As Decimal
dec1 = Convert.ToDecimal("100.00", _
Globalization.CultureInfo.GetCultureInfo("en-us"))
MsgBox(dec1.ToString())

On my system this returns "100,00" as expected.

The question is just if you want to take this effort just to have the
".00" visible in your code. If it's just for you to remind you of those
trailing zeros, why don't you just write
dec = 100 '100.00

Best regards,

Martin
From: Tom Shelton on
On 2010-02-12, Sheldon <Sheldon(a)discussions.microsoft.com> wrote:
> Hello -
>
> For some reason, I am unable to type 0.000 or 0.100 in code. Everytime I do
> it, it's automatically stripped away to 0.0 or 0.1.
>
> Is there a setting or something I need to change?

Why exactly would you want to do that?

--
Tom Shelton