Results 1 to 12 of 12

Thread: simple decimal question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I'm making this money balncing thing, now if the number that the user enters, and devides by 4, lets say that a number that has 3 digits after the . (decimal) how do I make it round it? to the last 2 decimals?
    NXSupport - Your one-stop source for computer help

  2. #2
    Guest
    If you have VB6, use the Round function.

    Code:
    MyNum = Round(MyNum, 2)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks Megatron
    NXSupport - Your one-stop source for computer help

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    also, how do I make it round down?
    NXSupport - Your one-stop source for computer help

  5. #5
    Guest
    I believe you would need to extract the 2nd and 3rd numbers after the decimal and write your own code to round down or up as you see fit. If you always want it rounded down, just delete everything after the second decimal place. Hope that makes sense.

  6. #6
    Guest
    To round a number, use the Int function.

    Code:
    MyNum = Int(MyNum)

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I'm not sure that I understand hellswraith, and, is there a way to round the number down the way megratron told me:
    mynum = Round(mynum, 2)
    is there a code like that that will always round down?
    NXSupport - Your one-stop source for computer help

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    the Int and Fix Functions always round down. I don't know one that always rounds down to a number of decimal places but you can make your own

    Code:
    Private Function RoundDown(ByVal Number As Double, ByVal DP As Integer)
    RoundDown = Int(Number * (10 ^ DP)) / (10 ^ DP)
    End Function

  9. #9
    Guest
    I don't know one that always rounds down to a number of decimal places
    The Round function does this.


  10. #10
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    that rounds to the nearest n dp, we want a function that rounds down

    Round(5.678,2) = 5.68
    RoundDown(5.678,2)=5.67


  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Why not just:
    Round(5.678-0.005,2) = 5.67
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks to all
    NXSupport - Your one-stop source for computer help

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