New P Basic Math Problem How do you calculate Percentage of a Number
Hi EveryOne
This is a project that I have been ·ask to do·by employer
As of right now I can not give all of the details.......................
................·but when the Project is done I will share with all of you on the Forum
I know that I have·This a another Post but this is a different question
http://forums.parallax.com/showthread.php?p=804156
http://forums.parallax.com/showthread.php?p=804554
http://forums.parallax.com/showthread.php?p=825473
Can this be done with P Basic Math and how would you do it
What I have will work but it would be nice to update more often
IF SL = 5000 THEN······· ' SL =· 5000· 10% of···· ·SL = 50000· 100%
T = 10························' T = % of what has been used
ELSE
IF SL = 10000 THEN
T = 20
ELSE
IF SL = 15000 THEN
T = 30
ELSE
IF SL = 20000 THEN
T = 40
ELSE
IF SL = 25000 THEN
T = 50
ELSE
IF SL = 30000 THEN
T = 60
ELSE
IF SL = 35000 THEN
T= 70
ELSE
IF SL = 40000 THEN
T = 80
ELSE
IF SL = 45000 THEN
T = 95
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·that you may have and all of your time finding them ![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/22/2009 1:40:06 PM GMT
This is a project that I have been ·ask to do·by employer
As of right now I can not give all of the details.......................
................·but when the Project is done I will share with all of you on the Forum
I know that I have·This a another Post but this is a different question
http://forums.parallax.com/showthread.php?p=804156
http://forums.parallax.com/showthread.php?p=804554
http://forums.parallax.com/showthread.php?p=825473
Can this be done with P Basic Math and how would you do it
What I have will work but it would be nice to update more often
IF SL = 5000 THEN······· ' SL =· 5000· 10% of···· ·SL = 50000· 100%
T = 10························' T = % of what has been used
ELSE
IF SL = 10000 THEN
T = 20
ELSE
IF SL = 15000 THEN
T = 30
ELSE
IF SL = 20000 THEN
T = 40
ELSE
IF SL = 25000 THEN
T = 50
ELSE
IF SL = 30000 THEN
T = 60
ELSE
IF SL = 35000 THEN
T= 70
ELSE
IF SL = 40000 THEN
T = 80
ELSE
IF SL = 45000 THEN
T = 95
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
![idea.gif](http://forums.parallax.com/images/smilies/idea.gif)
![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/22/2009 1:40:06 PM GMT
Comments
T = (SL/5000) * 10
You could handle the last option as a special case.
I've never used PBASIC so I don't know if it would be any better, though.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank You for your reply
I ran this as a Demo and the result is 4
Do I have some thing wrong with the way that I have this Please let me know
'·{$STAMP BS2}
' {$PBASIC 2.5}
· percent:
J······ VAR···· Nib········ · ' J is a index
F······ VAR···· Word······· ' F is the result
N······ VAR···· Word······· ' the variable going in
D····· CON····· 50000····· ' the 100% value
N = 43000
'
binary division loop
FOR J=15 TO 0··············· ' 16 bits
N=N//D<<1··················· ' remainder*2
F.BIT0(J)= N/D·············· ' next bit
NEXT
F = F**1000 + 5 / 10········ '· compute to 1% with roundoff
DEBUG HOME,· DEC· F
RETURN······················ ' F as percent 0 to 100
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank You for all of your help with all of my P Basic Math Calculation Questions·this has a lot of help and I have learned a lot doing this Project
for where I work··
I have a lot fun doing this Project·····
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
I try this and works very good· Thank You for your help and your reply
T = (SL/5000) * 10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam