Last active
April 9, 2019 14:19
-
-
Save femioladeji/586cec77c94b35ececb6d677060b2779 to your computer and use it in GitHub Desktop.
aws lambda function for rounding numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const roundNumber = (number, decimlPlaces) => { | |
return Number((Math.round(number + `e${decimlPlaces}`)) + `e-${decimlPlaces}`); | |
} | |
exports.handler = async (event) => { | |
const { number, places } = JSON.parse(event.body); | |
if (isNaN(number) || isNaN(places)) { | |
throw new Error('Invalid input supplied'); | |
} | |
const answer = roundNumber(number, places); | |
const response = { | |
statusCode: 200, | |
body: answer, | |
}; | |
return response; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment