aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

APPSYNC_JS support for parseInt, parseFloat and Number()

Open WolfWalter opened this issue 1 year ago • 5 comments

I tried to convert my object keys from string to numbers, but got "The code contains one or more errors. " as a response when I tried to use parseInt, parseFloat or Number().

WolfWalter avatar Jun 29 '23 07:06 WolfWalter

+1

myReturnObject = {}
stringFromPreviousResult = "52.525243"
myReturnObject.property = Number(stringFromPreviousResult)

What is the proper way to convert a string to a number with APPSYNC_JS runtime?

dsiebes avatar Jul 19 '23 14:07 dsiebes

As a workaround I used the unary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus

const test = '123';
const testNumber = +test;

WolfWalter avatar Jul 19 '23 15:07 WolfWalter