Data360 Analyze

 View Only
  • 1.  Roundening to next haft decimal.

    Employee
    Posted 12-13-2021 04:26

    Hi,

    I need make roundening to next 0.5.

    2.0 -> 2.0
    0.83 -> 1.0
    0.5 -> 0.5
    0.25 -> 0.5
    0.33 -> 0.5
    0.66 -> 1.0
    0.16 -> 0.5

    How I do this?

    Br: Kristian 



  • 2.  RE: Roundening to next haft decimal.

    Employee
    Posted 12-16-2021 02:20

    You could use the following Python code in a Transform node:

     

     

    ## ConfigureFields Script

    import math

    #Configure all fields from input 'in1' to be mapped
    #to the corresponding fields on the output 'out1'
    out1 += in1

    def RoundUpHalf(number):
    if number is Null:
    return Null
    else:
    return math.ceil(number * 2.0) / 2.0

    out1.result = float

     

    ## ProcessRecords Script

    #Copy all fields from input 'in1' to the corresponding output fields
    #in output 'out1'. Copies the values of the fields that have been setup
    #in the mapping defined in the ConfigureFields property
    out1 += in1

    out1.result = RoundUpHalf(fields.Value)