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)
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
Re: How to round Infinite Number
I was taught BODMAS :D
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
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?
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
Re: How to round Infinite Number
tg, Did you check the link I gave above...
Something from that site which I just saw...
Quote:
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...
Re: How to round Infinite Number
Multiplication == Division and subtraction == addition. Just with inverted numbers.
a * b = a / (1/b)
a + b = a - (-b)
So it doesn't matter whether you do a * b / c as (a*b)/c or a*(b/c).
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
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).
Re: How to round Infinite Number
Quote:
Originally Posted by
koolsid
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.
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:
http://upload.wikimedia.org/math/0/a...cfe86e1b11.png
You should evaluate the bottom part first:
Code:
T = m * v^2 / (1 - v^2 / c^2 + Math.Sqrt(1 - v ^2 / c ^2))
Re: How to round Infinite Number
Quote:
Originally Posted by
cicatrix
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
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
http://i45.tinypic.com/bfjj4l.png
Re: How to round Infinite Number
Quote:
Originally Posted by
NickThissen
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.
Quote:
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