Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to do computation in Liberty Basic

  1. Dec 30, 2005 #1
    I am trying to write a very simple program in Liberty Basic. The last step in the program gives me a answer in inches, and I want to convert it to feet. So I figured I would simply divide the answer in inches by 12, then multiply ONLY the decimal value by 12, and then I would have the value in feet and inches.
    So how do I multiply by only the numbers after the decimal point?
  2. jcsd
  3. Dec 30, 2005 #2
    When I said that I will have the answer in feet AND inches, I mean that it would say x feet and z inches. Just like someone would say if if they were talking about a length in feet that is not exactly x feet.
  4. Dec 30, 2005 #3


    User Avatar
    Staff Emeritus

    Does Liberty Basic have an INT() or FLOOR() function?
  5. Dec 30, 2005 #4
    Yes, it does have an Int() function.
  6. Dec 30, 2005 #5


    User Avatar
    Staff Emeritus

    Int() should give you the integer portion. If you need the decimal portion just subtract your floating point number by the integer portion.

    14.22-14 = .22
  7. Dec 30, 2005 #6
    But what if the number is a variable. Like in your example, sometimes the answer comes out to 14.22, but in some situations it would be 144.22, or a number other than 14.22. So how can I strip away the whole number and just leave the decimal portion for me to do calculations with. And how can I do that in a general way. I am not sure if I am being very clear, tell me if I am not. I am very new at this. By the way, thanks for the help. You are definetely pointing me in the right direction.
  8. Dec 30, 2005 #7
    Like I want to tell it to just leave 0.xx from the answer that it is giving me now so I can multiply only this decimal portion of the number by a fixed number (12).
  9. Dec 31, 2005 #8
    totalinches = 39.5
    onefoot = 12
    feet = int(totalinches/onefoot)
    inches = totalinches - (feet*onefoot)

    I think this will do what you want.

    If your language uses the backslash character for integer division, (returns only the whole portion of a division) you could write the feet caclulation as...
    feet = totalinches\onefoot
    Last edited: Dec 31, 2005
  10. Dec 31, 2005 #9
    Thanks BobK. That worked perfectly.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: How to do computation in Liberty Basic