how to calculate percentage
Archiver
Posts: 46,084
Hi, I am trying to calculate a percentage. How do I keep decimals places?
ie. I want to display something like 68/90 * 100. as it is now, i always get 0.
Thanks in advance.
ie. I want to display something like 68/90 * 100. as it is now, i always get 0.
Thanks in advance.
Comments
69 * 100 / 90
You will end up with 76 due to integer division. Just be careful that you
don't have any intermediate results that go past 16 bits (65535) -- this will
cause problems.
-- Jon Williams
You will end up with
In a message dated 4/5/2003 8:35:13 PM Central Standard Time,
mh_coelh@a... writes:
> Hi, I am trying to calculate a percentage. How do I keep decimals places?
> ie. I want to display something like 68/90 * 100. as it is now, i always
> get 0.
>
[noparse][[/noparse]Non-text portions of this message have been removed]
mh_coelh@a... writes:
> Hi, I am trying to calculate a percentage. How do I keep decimals places?
> ie. I want to display something like 68/90 * 100. as it is now, i always
> get 0.
>
> Thanks in advance.
>
6800/90 = 75.5, but the stamp will return 75, or 76 (cant remember).
If I remember correctly, the stamp will return only integer values.
If you need more resolution, 6800/9 = 755, then you will need to "pick off"
each digit to get 75.5.
There is probably a more elegant solution and as there are many very helpful
people in this forum, I am sure you get the information needed to solve your
current delima.
[noparse][[/noparse]Non-text portions of this message have been removed]
68*100/90
Just make sure that 68*100<65535
Al Williams
AWC
* Floating point math for the Stamp, PIC, SX, or any microcontroller
http://www.al-williams.com/awce/pak1.htm
>
Original Message
> From: mh_coelh@a...
> [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=fewKG-5AJ81jFUWlWyGRWp-tADnR4G4V9DpHsOS1ymS1hYRcCjG_tazHb3URW_plWQqH5km7lF17BkB2OOuF4kj-pIW1aA]mh_coelh@a...[/url
> Sent: Saturday, April 05, 2003 8:34 PM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] how to calculate percentage
>
>
> Hi, I am trying to calculate a percentage. How do I keep
> decimals places? ie. I want to display something like 68/90 *
> 100. as it is now, i always get 0.
>
> Thanks in advance.
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
>