One quick question. As there are only two apps available at the moment, I tested the Calculator app with 0.1+0.2 and I got 0.300...004, a common result we get in some programming languages. Just want to know how (and the best way) can we solve this issue when implementing a calculator app ourselves.
Hi,
This is a good point that I did not pay attention to it before.
When I saw your opinion, I first went to find out how this happens, which was interesting to me.
Then I thought to your question, how can we solve this issue?
At first, I thought we could round the number, but when I used the round method in JS, the result was zero! Then I searched it and realized that we can use the toFixed() method in JavaScript, when we put the digit on 1, the result is 0.3!
I want to know what is your answer to this question and is my answer correct?
Thank you very much for your excellent comment :)
Comment hidden by post author - thread only visible in this permalink
"I had the mistake of adding my github's account private key to the repository source. now I remove them all."
I don't know why I can't press "reply" on your answer, but here:
Well you deleted them, but they are still in the git commit history se we can still see them, so either:
Remove your repo and make a new one with commits from scratch (new initial commit)
I don't know git enough on the security parts, but if you don't want people to do bad things with your keys, invalidate them and generate them again (Idk how, sorry). :)
Yes, toFixed() is the JS way to round a Number and obtain a string. It will work if we know the number of fraction digits. If we divide numbers like 1/3, toFixed(1) will result in an answer 0.3 with a huge deviation compared to something like 0.333333.
Actually I am also looking for a good answer to this question. But I do have a workaround: to use toLocaleString with an en_US locale and maximumFractionDigits specified as 16 or less.
Btw, awesome work. It really feels like macOS and is also running fast!
I've seen a Windows 10 web app here in dev.to before but it was a bit laggy.
When you are 24, you will probably be working at Apple.
Btw, I just checked your GitHub repo, and immediately I have two things in my mind.
Why are there private and public keys in the repo source?
I thought you did this by using React or some other modern development framework/library but you did this all by vanilla HTML, JS and some jQuery for dragging support. You must have a deep understanding on how website works.
Comment hidden by post author
Comment hidden by post author - thread only visible in this permalink
Just change the keys if you've exposed a private key. As a general rule, never commit a private key on a public repository and really it's best to not ever and use something more secure like Hashicorp Vault or AWS's tools for secrets.
Comment hidden by post author
Comment hidden by post author - thread only visible in this permalink
One quick question. As there are only two apps available at the moment, I tested the Calculator app with
0.1+0.2
and I got0.300...004
, a common result we get in some programming languages. Just want to know how (and the best way) can we solve this issue when implementing a calculator app ourselves.Hi, Try this.
This works too!
You should use bigNumber to fix it. (Mathjs, Bignumberjs). This is my example: github.com/nguyenvannghi/calc-reac...
Hi,
This is a good point that I did not pay attention to it before.
When I saw your opinion, I first went to find out how this happens, which was interesting to me.
Then I thought to your question, how can we solve this issue?
At first, I thought we could round the number, but when I used the round method in JS, the result was zero! Then I searched it and realized that we can use the toFixed() method in JavaScript, when we put the digit on 1, the result is 0.3!
I want to know what is your answer to this question and is my answer correct?
Thank you very much for your excellent comment :)
I don't know why I can't press "reply" on your answer, but here:
Well you deleted them, but they are still in the git commit history se we can still see them, so either:
I don't know git enough on the security parts, but if you don't want people to do bad things with your keys, invalidate them and generate them again (Idk how, sorry). :)
Yes,
toFixed()
is the JS way to round aNumber
and obtain a string. It will work if we know the number of fraction digits. If we divide numbers like1/3
,toFixed(1)
will result in an answer0.3
with a huge deviation compared to something like0.333333
.Actually I am also looking for a good answer to this question. But I do have a workaround: to use
toLocaleString
with anen_US
locale andmaximumFractionDigits
specified as16
or less.That's right,
it's a great idea to use
toLocaleString
with anen_US
locale andmaximumFractionDigits
specified as16
or less. 👍Btw, awesome work. It really feels like macOS and is also running fast!
I've seen a Windows 10 web app here in dev.to before but it was a bit laggy.
When you are 24, you will probably be working at Apple.
Btw, I just checked your GitHub repo, and immediately I have two things in my mind.
Thanks :)
For your first question, I had the mistake of adding my github's account private key to the repository source.
now I remove them all.
I'm glad about that :)
I had no idea what vanilla meant 😅(of course, now I know).
you are 14? really?
btw, be careful on how you remove those private keys. one commit removing the files is not enough
Just change the keys if you've exposed a private key. As a general rule, never commit a private key on a public repository and really it's best to not ever and use something more secure like Hashicorp Vault or AWS's tools for secrets.
To OP: See this for GitHub's official guide about removing sensitive data: docs.github.com/en/authentication/...