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

Calculation problem

pusinkpusink Posts: 68
edited 2009-12-01 06:17 in Propeller 1
the calculation is like this...........

LONG S

S := (390/300) * 60
i get value S = 60....

how to get·S = 78 ?

how to solve with *.spin?

·

Comments

  • KyeKye Posts: 2,200
    edited 2009-12-01 04:39
    Do:

    S := ((390 * 60) / 300)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-01 04:40
    s := 390 * 60 / 300

    390 / 360 == 1 in integer arithmetic.

    -Phil
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-12-01 06:17
    In other words, the operators * and / perform only integer math, so you will not get any decimal values in your intermediate calculation.

    If you want to work with decimal values, then you need to use one of the objects like FloatMath, etc. And you need to read the rules concerning such operations: for example for a float, you need to use a decimal when you assign a value, like, ThisNumber := 123.0 You could not do float math with ThisNumber if you did not include that decimal point.

    smile.gif


    obex.parallax.com/objects/53/

    Post Edited (ElectricAye) : 12/1/2009 6:30:29 AM GMT
Sign In or Register to comment.