Hi. I'm trying to multiply fractions. How can I take '1 1/2' and multiply it to get 3?
(is there some special format like '1-1/2' that I need to use to multiply it?)
Thanks
Hi. I'm trying to multiply fractions. How can I take '1 1/2' and multiply it to get 3?
(is there some special format like '1-1/2' that I need to use to multiply it?)
Thanks
Its much easier to use decimals, however you can use "fractions" by simple addition and division. For your example, 1 1/2 = 1+(1/2) although this can also be written 1+1/2 since division takes precedence.
Agree with darkagn.
BUT multiplication - be careful this will also take precedence (BODMAS, PODMAS, BIDMAS, PIDMAS - whatever you want to call it).
So place the term to be multiplied within brackets, otherwise you'll just multiply the integer or the fraction.
e.g.
echo (1 + 1/2) * 2; //gives 3
echo 1 + 1/2 * 2; //gives 2
echo 2 * 1 + 1/2; //gives 2.5
Awesome. Thanks!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.