Diff between CSng and CDbl

Discussion in 'ASP General' started by Laphan, Nov 18, 2005.

  1. Laphan

    Laphan Guest

    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
     
    Laphan, Nov 18, 2005
    #1
    1. Advertising

  2. Diff between single and double?

    Size

    See inline:
    Laphan wrote:
    > 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

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Nov 18, 2005
    #2
    1. Advertising

  3. Laphan

    Laphan Guest

    Many thanks Bob

    This has put my mind at ease.

    Rgds Laphan

    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    Diff between single and double?

    Size

    See inline:
    Laphan wrote:
    > 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

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Laphan, Nov 18, 2005
    #3
  4. Laphan

    Patrice Guest

    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...

    --
    Patrice

    "Laphan" <> a écrit dans le message de
    news:...
    > 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
    >
    >
     
    Patrice, Nov 18, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    513
    Joe Smith
    Jun 29, 2004
  2. Berrucho
    Replies:
    2
    Views:
    641
    Infant Newbie
    Dec 5, 2003
  3. A Traveler

    Diff CSS styles for diff INPUT TYPE='s?

    A Traveler, Aug 31, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,929
    Steve Fulton
    Aug 31, 2004
  4. Santa
    Replies:
    1
    Views:
    1,085
    Mark A. Odell
    Jul 17, 2003
  5. Replies:
    4
    Views:
    146
    Dr John Stockton
    Aug 22, 2006
Loading...

Share This Page