Search code examples
karateintuit-partner-platform

How do i round off float values to integer in karate


I have a floating point value of 0.99996 and want to round off to the nearest Integer. How do i do that in karate?


Solution

  • * def val1 = 0.99996
    * print val1
    * def val2 = Math.round(val1)
    * print val2
    

    Note that before Karate 1.0 you may need to do this to remove the decimal point:

    * def val2 = ~~Math.round(val1)
    

    Also refer to type-conversion: https://github.com/intuit/karate#floats-and-integers