Gentlemen,
I would like to round a value three decimal places. Is this possible?
example:
#540=3.333333333
your help here
#540=3.333
Thank You
Gentlemen,
I would like to round a value three decimal places. Is this possible?
example:
#540=3.333333333
your help here
#540=3.333
Thank You
3.333 should be fine as long as you don't want to multiply it by three and expect to get 10.
Why do you need to round it? Saving ink?
Super X3. 3600rpm. Sheridan 6"x24" Lathe + more. Three ways to fix things: The right way, the other way, and maybe your way, which is possibly a faster wrong way.
If I remember correctly, most systems have ROUND and FIX. Not as simple as it seems though.
#540=3.333333333
#540=#540 * 10000 (results in 33333.33333)
#540=FIX[#540] (results in 33333.)
#540=#540 / 10 (results in 3333.3)
#540=ROUND[#540] (results in 3333.0)
#540=#540 / 1000 (results in 3.3330)
I think that is the way it works.
A one-liner would be #540=[[ROUND[#540*1000.]]/1000.]
Be aware that rounding numbers can sometimes give incorrect results, especially if you multiply the original number by a very large amount. Test your macro with different values and add extra logic as required to ensure the correct result is always given. FIX will round down, FUP will round up.
DP
I would like to elaborate a little bit on the previous posts
The ROUND[#i] function when used in a statement (if, while, mathematical operations etc) will round off from the first decimal place to the nearest integer. However if the round function is used when a movement is commanded it rounds to the smallest commandable movement.
For example, if the smallest movement you can command is .0001 then:
#100=1.34528
G1X[ROUND[#100]]
will move to X1.3453
But if you were to say
#101=ROUND[#100]
then #101 will take on the value of 1
FUP truncates the decimal places and changes the value to the next integer
#100=1.24 #101=-1.24
FUP[#100]=2
FUP[#101]=-2
FIX does the same thing, but simply truncates the decimal places and keeps the same integer to the left of the decimal place. Using the previous variables,
FIX[#100]=1
FIX[#101]=-1
with negative values, think of these functions as first taking the absokutle value, applying the function, and then putting the negative sign back to the new value
It is important to note that unlike the previous poster said, FIX and FUP do NOT perform rounding. They truncate (remove) the decimal points and provide you with an integer.
ROUND[3.9999] will return a value of 4, as will FUP, but FIX will return a value of 3. Contrast this with ROUND[3.1111] which will return a value of 3, but FUP and FIX still return the same respective values of 4 and 3, just as they did when the value operated on was 3.9999
It's a bit of a semantics game and he was not exactly wrong, just the term rounding is used incorrectly in the case of FIX and FUP, but it is important to know the distinction.
Cheers
Well explained, and absolutely correct.
In the context of Fanuc control, there is, what I call, implicit rounding.
Because of this, the result would be same even without ROUND function in the above example.
But G1 X1.34528 would place the tool at 1.3452, truncating the extra digit.
See the attachment for details.