Diff between CSng and CDbl

L

Laphan

Hi All

I understand that all asp classic vars are variants and to always make sure
that you are working with the type that you want it is best to use these
built-in Cxx() functions, but I'm confused about whether I should use CSng
or CDbl for my calcs.

I don't think they will ever be more than say 6 decimal places (at the very
most usually 2 or 3) and the value the other way won't be in the millions
(chance would be a fine thing!!) so should I be using CSng or CDbl?

Is there any kind of performance degradation in using one over the other?

Is there any kind of accuracy degradation in using one over the other?

Your comments would be appreciated.

Rgds Laphan
 
B

Bob Barrows [MVP]

Diff between single and double?

Size

See inline:
Laphan said:
Hi All

I understand that all asp classic vars are variants and to always
make sure that you are working with the type that you want it is best
to use these built-in Cxx() functions, but I'm confused about whether
I should use CSng or CDbl for my calcs.

I don't think they will ever be more than say 6 decimal places (at
the very most usually 2 or 3) and the value the other way won't be in
the millions (chance would be a fine thing!!) so should I be using
CSng or CDbl?

I would choose single.
Is there any kind of performance degradation in using one over the
other?

No, not that you would notice unless you were performing millions of loops
with it.
Is there any kind of accuracy degradation in using one over the other?

No


Bob Barrows
 
L

Laphan

Many thanks Bob

This has put my mind at ease.

Rgds Laphan

Diff between single and double?

Size

See inline:
Laphan said:
Hi All

I understand that all asp classic vars are variants and to always
make sure that you are working with the type that you want it is best
to use these built-in Cxx() functions, but I'm confused about whether
I should use CSng or CDbl for my calcs.

I don't think they will ever be more than say 6 decimal places (at
the very most usually 2 or 3) and the value the other way won't be in
the millions (chance would be a fine thing!!) so should I be using
CSng or CDbl?

I would choose single.
Is there any kind of performance degradation in using one over the
other?

No, not that you would notice unless you were performing millions of loops
with it.
Is there any kind of accuracy degradation in using one over the other?

No


Bob Barrows
 
P

Patrice

Shouldn' t have any visible effect on performance unless you have very
numerous calculations. Check the VBScript doc for a description of the
Single and Double types :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbsDataType.asp

Not sure but your post may lead to think that you have numerous conversions
in your code. You have to do this once so that the variable you are using
have then the proper subtype (especially true for example with user input
that is returned as text). You don't need to do that in each and every
calculation.

The point is that ALL variables are variants. Even CSng and CDbl returns a
variant variable with the proper subtype. So once this is done for the
variable used for following calculations, converting again and again is
useless.

Likely picky and off topic but wanted to clarify this if needed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top