Forum Discussion

patan's avatar
patan
New Contributor III
5 years ago
Solved

Using the parsed Float value in string

I have double value coming from the source as a string.
Source value:

“NTGEW” : “3.400”

I am using parseFloat() function to convert the string into double value.

parseFloat($NTGEW) ===> 3.4

The parseFloat function is working as expected when it is the only function as show above.

But if I use the same function with string concatenation it is appending the double value with trailing zeros as shown below:

“Input Value” + parseFloat($NTGEW) ===> “Input Value 3.400”

The expected value should be ===> “Input Value 3.4”

Any suggestions would be appreciated.floatIssue_2020_10_08.slp (4.8 KB)

  • Maybe initially I didn’t understand well your issue.
    You can use the following statement with regex:
    "Input Value “+ ((parseInt($NTGEW) == parseFloat($NTGEW)) ? parseInt($NTGEW).toString() : (parseFloat($NTGEW).toString()+“0”).match(”(.*d?[1-9])0+$")[1])*

    So, I did tests with few cases and got the following result:

    And here is updated pipeline:
    floatIssue_2020_10_08_v2.slp (5.2 KB)

    Please let me know if this version works as expected.

    /Lazo

4 Replies

  • lazo_ilijoski's avatar
    lazo_ilijoski
    New Contributor III

    Maybe initially I didn’t understand well your issue.
    You can use the following statement with regex:
    "Input Value “+ ((parseInt($NTGEW) == parseFloat($NTGEW)) ? parseInt($NTGEW).toString() : (parseFloat($NTGEW).toString()+“0”).match(”(.*d?[1-9])0+$")[1])*

    So, I did tests with few cases and got the following result:

    And here is updated pipeline:
    floatIssue_2020_10_08_v2.slp (5.2 KB)

    Please let me know if this version works as expected.

    /Lazo

    • patan's avatar
      patan
      New Contributor III

      Thank you @lazo.ilijoski
      I worked with it but, the problem is that if I have the below two values,

      42.000
      42.568

      I want the below output

      42
      42.568

      If I use the parseFloat($NTGEW).toFixed(1) then it will give me the below output

      42.0
      42.6