Results 1 to 6 of 6

Thread: [resolved]rounding answer

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Resolved [resolved]rounding answer

    VB Code:
    1. Text20 = CInt(Text15.Text) * CInt(Text13.Text) + CInt(Text11.Text) * 12 / 52 * CInt(Text13.Text)

    how can i round the text20 to 2 decimal places?
    Last edited by theasker; May 23rd, 2005 at 05:35 AM.

  2. #2
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: rounding answer

    Try This

    Decimal.Round( YourMathExpression, 2)

    Note that decimal.Round employs bankers rounding. (Do a google search if you don't know what this is)

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: rounding answer

    If you want decimal places I wouldn't use int(egers) as these do no have places... normally

    I'd use doubles and only format the end resulting calculation otherwise you'd get calculation errors from one to another calc.

    cdbl for the function.
    Although I think there may be problems with the accuracy as it is floating point :/ other people can comment on that.
    Code:
    dblTemp = Cdbl(Text15.Text) * Cdbl(Text13.Text) + (Cdbl(Text11.Text) * 12) / (52 * Cdbl(Text13.Text))
    Text20 = format(dblTemp,"#,#0.00")
    Experiment with it and see which way gives you the results you want.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Re: rounding answer

    no luck..

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: rounding answer

    Here is an idea for you:

    Create a new variable as a string version of your number.
    With that, split the number using Mid$() to get the actual decimal you want to check.
    Then, turn that back into a number and check if it is below or above 5 and go from there

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Resolved Re: rounding answer

    thanx man!! when i posted
    no luck
    that was for the guy that told me to use decimal.round... but u posted just before me lol, and thanx! it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width