Results 1 to 13 of 13

Thread: How to round Infinite Number

  1. #1

    Thread Starter
    Lively Member Brian Henry's Avatar
    Join Date
    Oct 2005
    Posts
    94

    How to round Infinite Number

    I am trying to round a number but I keep getting an Infinity number. How do I round this.

    4000 / 7135 * 100

    Here's the code I've tried.
    Code:
    Round(readVals(0) / Scaling1 * 100 + ActualValueLow1, 2)
    
    FormatNumber(readVals(0) / Scaling1 * 100 + ActualValueLow1, 2)
    Brian Henry
    Visual Studio 2001 to 2019
    Java/Android
    ISaGRAF

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to round Infinite Number

    There's an order of operations involved, and I think it is interfering with your calculations:

    I was taught this to help remember the order in which things will take precidence:
    Please
    Excuse
    My
    Dear
    Aunt
    Sally

    -meaning-
    Parenthesis
    Exponential
    Multiplication
    Division
    Addition
    Subtraction

    So... since there is no parenthesis, the first thing that is done is 7135 * 100 =713500
    Then the division
    4000 / 713500 = 0.0056061667834618079887876664330764

    Then your ActualValueLow will get added.... something tells me that's not what you wanted.
    But rather:
    ((4000 / 7135) * 100) + ActualValueLow
    ((.5606) * 100) = 56.06
    56.06 + ActualValueLow


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How to round Infinite Number

    I was taught BODMAS

    B
    Brackets first
    O
    Orders (ie Powers and Square Roots, etc.)
    D
    Division (tg: I just noticed you have multiplication first?)
    M
    Multiplication
    A
    Addition
    S
    Subtraction
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to round Infinite Number

    I don't understand the question?

    Dim dd As Double = 4000 / 7135 * 100 '=56.061667834618078

    What should dd look like after rounding?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to round Infinite Number

    Yup... multiplication comes first... it should be BOMDAS... not BODMAS .... think about it, Addition and Multiplication are "the same" ... additive... you do your additives first before you take away (division and subtraction).

    -tg

    More monkiers:
    Mary's Violet Eyes Made John Stay Up Night Proposing....
    The planets:
    Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto (back in the dark ages when Pluto was still considered a planet). I guess John just stays up nights... no more proposals.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How to round Infinite Number

    tg, Did you check the link I gave above...

    Something from that site which I just saw...

    The only strange name is "Orders". "Exponents" is used in Canada, and so you might prefer "BEDMAS". There is also "Indices" so that makes it "BIDMAS". In the US they say "Parenthesis" instead of Brackets, so they say "PEMDAS"
    In US ~~> it's Multiplication first

    I went further down on that page and realized that both are correct...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to round Infinite Number

    If that's the case... why do I get a different result?

    4000 / 7135 * 100
    (4000 / 7135) * 100 = 56.06
    4000 / (7135 * 100) = 0.005606
    BUT
    (4000 * 100) / 7135 = 56.06

    Personally, I like to include the parenthesis, that way there is no question as to the order of operations.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: How to round Infinite Number

    Well, writing "a / b * c" is arbitrary. It could mean (a/b)*c or a/(b*c), which indeed is not the same.

    As far as I know there is no rule on whether you do division or multiplication first, just don't write a/b*c.

    In physics, for example, you often see formulas that read:
    F = -G/4 pi r2
    This means F = -G / (4 pi r2)

    But you also see
    E = 1/2 m v2
    which means
    E = (1/2) * m * v2

    The only reason no confusion arises is because these formules are well known. In any other situation, just don't use it, use parenthesis or actual fractions (bit hard in text of course).

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to round Infinite Number

    Quote Originally Posted by koolsid View Post
    tg, Did you check the link I gave above...

    Something from that site which I just saw...



    In US ~~> it's Multiplication first

    I went further down on that page and realized that both are correct...
    They should "parentheses" everywhere. "brackets" gets used as an umbrella term and people say "round brackets", "square brackets", "curly brackets" and "angle brackets" like it's primary school when they should say "parentheses" (), "brackets" [], "braces" {} and "chevrons" <>. I think chevrons may have another name too that I can't recall.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: How to round Infinite Number

    When you see a * b / c this means ONLY that you have to multiply a by b and then divide the result by c. Without parentheses the order of operations with equal priority goes from left to right (and * and / are of equal priority).

    In math formulas like this:



    You should evaluate the bottom part first:

    Code:
    T = m * v^2 / (1 - v^2 / c^2 + Math.Sqrt(1 - v ^2 / c ^2))

  12. #12
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: How to round Infinite Number

    Quote Originally Posted by cicatrix View Post
    When you see a * b / c this means ONLY that you have to multiply a by b and then divide the result by c.
    You can divide b by c and multiply that by a, or divide a by c and multiply that by b. It's all the same thing, so in this case you don't need parentheses.
    (a * b) / c is the same as a * (b / c) or even (a / c) * b.

    Quote Originally Posted by cicatrix View Post
    Without parentheses the order of operations with equal priority goes from left to right (and * and / are of equal priority).
    I don't know of any such rule and in 'my field' (physics) this rule is often not true. For another example, this:
    I = P / 4 pi r2
    is a well known formula and it is written like that very often, even though it should be written (and calculated) as
    I = P / (4 pi r2)

    If the rule you mention holds true always then it would have been
    I = (P / 4) pi r2
    something completely different.

    But this notation is not official and is simply wrong because it is ambiguous.

    Also, I think exponents are evaluated right-to-left, so that:
    2^3^4^5 = 2^(3^(4^5)) = giant overflow (something like (10244)5
    and not ((2^3)^4)^5 = 1152921504606846976


  13. #13
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: How to round Infinite Number

    Quote Originally Posted by NickThissen View Post
    You can divide b by c and multiply that by a, or divide a by c and multiply that by b. It's all the same thing, so in this case you don't need parentheses.
    (a * b) / c is the same as a * (b / c) or even (a / c) * b.
    Well, maybe my example did not illustrate my point. Here:

    a / b * c means you should divide a / b and then multiply the result by c
    in this case
    (a / b) * c <> a / (b * c)

    so, without parentheses the operators are evaluated from left to right.

    I don't know of any such rule and in 'my field' (physics) this rule is often not true. For another example, this:
    I = P / 4 pi r2
    is a well known formula and it is written like that very often, even though it should be written (and calculated) as
    I = P / (4 pi r2)
    I = P / 4 * pi * r2 in terms of math should be evaluated as:
    1. a = r ^ 2
    2. b = P / 4
    2. c = b * pi
    3. d = c * a

    And any programming language will evaluate it in the precisely that order.

    In Physics (see my post above) they use fractions and your example should be written like this:

    Code:
              P
    I = --------------
         4 * Pi  * r2

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