Set decimal places

Discussion in 'ASP General' started by Dean G, Nov 7, 2004.

  1. Dean G

    Dean G Guest

    Hi, I need to truncate a number to two decimal places without rounding.
    All the functions i;ve tried tend to round up the numbers. Also i cant
    use any string functions to limit the size because the size can vary.
    example, 34.56998 must be set to 34.56
    thanx
    any help is greatly appreciated
    btw this is using asp vbscript


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dean G, Nov 7, 2004
    #1
    1. Advertising

  2. Dean G

    Evertjan. Guest

    Dean G wrote on 07 nov 2004 in microsoft.public.inetserver.asp.general:

    > Hi, I need to truncate a number to two decimal places without rounding.
    > All the functions i;ve tried tend to round up the numbers. Also i cant
    > use any string functions to limit the size because the size can vary.
    > example, 34.56998 must be set to 34.56
    > thanx
    > any help is greatly appreciated
    > btw this is using asp vbscript
    >


    Use a regex replace:

    function round2(x)
    if instr(x,".")=0 then x = x & "."
    Set re = New RegExp
    re.Pattern = "(\d*(\.\d{1,2})?)\d*"
    round2 = re.Replace(x & "00", "$1")
    end function

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
    Evertjan., Nov 7, 2004
    #2
    1. Advertising

  3. Dean G

    Dean G Guest

    Thanx Evertjan,
    Thats pretty clever i can see why i didnt think of that, it did the
    trick perfectly.
    Thanx for the help


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dean G, Nov 8, 2004
    #3
  4. Dean G

    Jos Guest

    Dean G wrote:
    > Hi, I need to truncate a number to two decimal places without
    > rounding. All the functions i;ve tried tend to round up the numbers.
    > Also i cant use any string functions to limit the size because the
    > size can vary. example, 34.56998 must be set to 34.56
    > thanx
    > any help is greatly appreciated
    > btw this is using asp vbscript
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!


    dTruncated = (Int(d*100))/100
    or
    dTruncated = (Fix(d*100))/100

    --

    Jos
    Jos, Nov 8, 2004
    #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. Eoin Mcloughlin

    Decimal places and huge fractions.

    Eoin Mcloughlin, Feb 11, 2004, in forum: Perl
    Replies:
    5
    Views:
    1,598
    Eoin Mcloughlin
    Feb 13, 2004
  2. Curt_C [MVP]

    Re: beginner: prob with decimal places

    Curt_C [MVP], May 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    329
    Curt_C [MVP]
    May 18, 2004
  3. Curt_C [MVP]

    Re: beginner: prob with decimal places

    Curt_C [MVP], May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    537
    Curt_C [MVP]
    May 18, 2004
  4. Harry

    Remove Decimal Places

    Harry, Jun 3, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    8,925
    VB Programmer
    Jun 3, 2004
  5. Bharat Bhushan

    Decimal Places

    Bharat Bhushan, Aug 8, 2003, in forum: Java
    Replies:
    2
    Views:
    481
    Lee Weiner
    Aug 8, 2003
Loading...

Share This Page