How to convert the decimal number to integer in robot framework

Hi,
I tried to convert Decimal(‘848.000000000000000000’) number to integer and getting the error message like “AttributeError: ‘int’ object has no attribute ‘lower’”

Code in Robot framework

${result}[${rowno}][7]= Decimal(‘848.000000000000000000’)
${Query_Description} = Set Variable ${result}[${rowno}][7]
${KL1}= run keyword and continue on failure convert to integer ${Query_Description}
log to console The Mesurement Value ${KL1}

Getting the error message like "
AttributeError: ‘int’ object has no attribute ‘lower’


Integer_issue1

*** Settings ***
library   foo.py
*** Test Cases ***
Test Case 1
  ${val}=   Get Dec
  ${KL1}=   run keyword and continue on failure   convert to integer      ${val}
  log to console    The Mesurement Value ${KL1}
from decimal import Decimal
def get_dec():
    return Decimal("848.000000000000000000")

This works and logs out 848 as it should … Your issue is most likely somewhere else outside of your shared code. I’d start by opening log.html and seeing what exact keyword is triggering that failure. Its way more present there than in the console.

1 Like

Hello @samta,

As rasjani said, the issue might be coming from somewhere else. For example, the FOR loop that you have implemented seems bit off. Also, rasjani has provided a good example but here is one basic example using RF builtin:

Convert to integer
    ${number}         Set Variable    848.000000000000000000
    ${KL1}            run keyword and continue on failure    convert to number    ${number}    0
    log to console    Converted floating point value is ${KL1}
    ${KL2}            run keyword and continue on failure    convert to integer    ${KL1}
    log to console    Converted integer value is ${KL2}

The result is:
…Converted floating point value is 848.0
…Converted integer value is 848
Convert to integer | PASS |

2 Likes

Thanks @Pramesh for your help. Now my code is working fine.
I am using for loop to get all measurement value from SQL query:
image

1 Like

Thanks @rasjani for your help to clear the basic concept for integer. It helps me to run my code.