Shop OBEX P1 Docs P2 Docs Learn Events
Percentage problem — Parallax Forums

Percentage problem

sassas Posts: 2
edited 2005-10-05 14:23 in BASIC Stamp
I am trying to develop an app that compares two values and takes action based on that comparison. This is an easy task with floating point but I’m not very knowledgeable on how to handle this without. ·
·
Input A will vary from 255 to 100 Input B will vary between· 60% and 98% of input A.
·
·
Using floating point math I would use the following logic
·
Get A
Get B
·
·
SELECT ·B/A
CASE > .95
GOTO ·
CASE > .90
GOTO
CASE > .80
GOTO
CASE > .70
GOTO
CASE < .71
GOTO
·
Since floating point is not available how can I accomplish this with the BS2?
·
Thanks,

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-10-04 16:04
    Look in the Stamp documentation at the operator */, you'l find it has the effect of multiplying a number by a fraction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-04 23:02
    Convert everything to 100ths and do it like this:

    · testVal = bVal * 100 / aVal
    · SELECT testVal
    ··· CASE > 95
    ····· ' code·here
    ··· CASE 91 TO 95
    ····· ' code·here·
    ··· CASE 81 TO 90
    ····· ' code here
    ··· CASE 71 TO 80
    ····· ' code here
    ··· CASE ELSE
    ····· ' code here
    · ENDSELECT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • sassas Posts: 2
    edited 2005-10-05 01:18
    Thanks Jon,

    That was easy and should have been obvious.

    Thanks again.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-10-05 14:23
    Thanks Jon, definitely much more simple than my suggestion. As always there is more than one way to skin a cat, but some ways you're less likely to cut yourself in the process.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
Sign In or Register to comment.