586,070 active members*
3,543 visitors online*
Register for free
Login
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Rounding a value three decimal places

    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

  2. #2
    Join Date
    Jun 2007
    Posts
    3757
    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.

  3. #3
    Join Date
    May 2004
    Posts
    4519
    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.

  4. #4
    Join Date
    Aug 2009
    Posts
    684
    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

  5. #5
    Join Date
    Oct 2011
    Posts
    0
    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

  6. #6
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by SirDenisNayland View Post
    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
    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.
    Attached Files Attached Files

Similar Threads

  1. decimal places
    By stevieboy in forum Mastercam
    Replies: 12
    Last Post: 08-01-2010, 07:56 PM
  2. need 5 decimal places
    By kendo in forum Haas Mills
    Replies: 12
    Last Post: 04-13-2009, 06:43 PM
  3. putting in decimal places.
    By G00 in forum G-Code Programing
    Replies: 4
    Last Post: 08-27-2008, 08:27 PM
  4. Favrite places to buy tooling?
    By JDsto in forum Mini Lathe
    Replies: 3
    Last Post: 12-26-2007, 04:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •