Ad Widget

Collapse

Javascript prepocessing - simple addition turns result in string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noobz
    Senior Member
    • Jun 2020
    • 105

    #1

    Javascript prepocessing - simple addition turns result in string

    I simply need to add 0.7 to a returned value in preprocessing, however it seems that javascript is taking 0.7 as a string and converting the whole result to a string.

    If I do:
    return value+0.7
    or any formatting variation of that I've tried, using a test value of 26, it will result in 260.7

    Upon testing this further, it seems that using almost exactly the same formula as the documentation shows, any simple addition is converted to a string.

    i.e. return (value - 32) will return the correct figure such as 0 for a test value of 32

    However, addition is broken.

    return (value + 32) will result in 3232
  • Noobz
    Senior Member
    • Jun 2020
    • 105

    #2
    Originally posted by splitek
    This is javascript.
    JavaScript string operators covering description, example code, output of example, online practice editor and explanation by w3resource.com

    https://stackoverflow.com/questions/...rings-together

    Code:
    return (+value + 32);
    return (parseInt(value) + 32);
    That works, thank you. I had tried to use Number() and something else I can't recall however simply using +value works

    Comment

    Working...