How to do computation in Liberty Basic

  • Thread starter Thread starter Nothing000
  • Start date Start date
  • Tags Tags
    Computation
Click For Summary

Discussion Overview

The discussion revolves around programming in Liberty Basic, specifically focusing on converting a measurement from inches to a combination of feet and inches. Participants explore how to isolate the decimal portion of a floating-point number for further calculations.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant seeks to convert a measurement in inches to feet and inches by dividing by 12 and isolating the decimal value.
  • Another participant clarifies that the goal is to express the result in the format of "x feet and z inches."
  • A question is raised about the availability of INT() or FLOOR() functions in Liberty Basic.
  • It is confirmed that Liberty Basic has an Int() function, which can be used to obtain the integer portion of a number.
  • A method is proposed to obtain the decimal portion by subtracting the integer portion from the original number.
  • A participant expresses uncertainty about how to apply this method to a variable, seeking a general solution for isolating the decimal portion.
  • A code snippet is provided that demonstrates how to calculate feet and inches from a total in inches, including a note about integer division.
  • A participant confirms that the provided solution worked for their needs.

Areas of Agreement / Disagreement

Participants generally agree on the methods for isolating the decimal portion of a number and converting inches to feet and inches, but there is no explicit consensus on the best approach for all variable cases.

Contextual Notes

The discussion includes assumptions about the behavior of floating-point arithmetic and the specific functions available in Liberty Basic, which may vary based on context or version.

Nothing000
Messages
403
Reaction score
0
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?
 
Technology news on Phys.org
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.
 
Does Liberty Basic have an INT() or FLOOR() function?
 
Yes, it does have an Int() function.
 
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
 
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 definitely pointing me in the right direction.
 
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).
 
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:
Thanks BobK. That worked perfectly.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
Replies
29
Views
6K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 27 ·
Replies
27
Views
5K
  • · Replies 14 ·
Replies
14
Views
2K
  • Sticky
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 32 ·
2
Replies
32
Views
5K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K