Rounding Numbers Failing #6228
Replies: 1 comment
-
Posted at 2023-09-18 by rigrigrig It breaks because Espruino doesn't support default parameter values, Posted at 2023-09-18 by @gfwilliams Thanks - it is slightly concerning that it doesn't cause an error though. It seems that in Espruino, Posted at 2023-09-20 by charlie Thanks for the feature link. Shame no1 linked to it (and I wasn't able to find it) when I was asking about which version of javascript Espruino is based on. Maybe I was looking on bangle documentation only. My code snippet is abit miss leading as its from a typescript file not a direct javascript file. I am compiling it down to es5 when building. I should probably check what typescript is doing with default params when the target output is es5. The main concern is as Gordon says, not that it isn't supported, but that no error is fired. Posted at 2023-09-20 by @fanoush
You got that link right here https://forum.espruino.com/conversations/388506/#17058616 when you asked :-) Posted at 2023-09-20 by @gfwilliams :) yes - literally second line. Also, if you give us some idea of what search words you'd likely search for on the Espruino site to find the info then I can add those to the keywords list for the page so it comes up for more people. Same for any page really - I pretty much never get any PRs for this, but if there's a page that you found that didn't come up when you searched, there's a link at the bottom of the page that goes to GitHub (eg https://github.com/espruino/EspruinoDocs/blob/master/info/Features.md) and you can add to the Posted at 2023-09-21 by charlie yeh, my mistake. Clearly I am terrible at reading! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-09-18 by charlie
I have added a round function to my code libs to round numbers to a certain number of decimals. It looks roughly as follows;
expected outcome:
This passes all local unit tests compiling in es5, es6 and esnext. It also works fine on a couple of online javascript compilers I tested (codepen, Typescript playground) - and its exact copy of code others have used for doing the same thing.
If I run this code on the bangle emulator or the bangle2 watch directly I get "NaN" returned.
Beta Was this translation helpful? Give feedback.
All reactions