Skip to content

Instantly share code, notes, and snippets.

@femioladeji
Last active April 9, 2019 14:19
Show Gist options
  • Save femioladeji/586cec77c94b35ececb6d677060b2779 to your computer and use it in GitHub Desktop.
Save femioladeji/586cec77c94b35ececb6d677060b2779 to your computer and use it in GitHub Desktop.
aws lambda function for rounding numbers
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