Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Why not .099? or 0.09999?
are you aware that between any two real number there are infinte number of real numbers? -
You subtract 0.01 - and may run into floating point math issues with the precision. Decimal fractions are a bad idea in floating point. Instead, use stuff like 1/2, 1/4, 1/8 and so on.
-
FuckTS1965y@Fast-Nop @Fast-Nop I want when the code finds 0.1 he decrements it to 0.09 automatically, 0.01 decrements to 0.009 etc etc, get it?
-
@FuckTS
You should start with a decrement of 1 and divide it by ten until the decremented value is positive. -
@FuckTS oh ffs.
just pre generate a hashmap by hand.
use the 0.9 as key, value is a tuple of (1, 0.8).
searching it will be an O(1) thing, and you will avoid overflow/underflow issues along with the js string + number crapshoot.
alternative, and a very dumb solution is to convert the whole thing in to a positive integer issue. just multiply everything by 1e10, and solve from there. -
Root825285yDon't use math.
Use a string.
You'll avoid all of the headaches that way at the cost of some memory and unnoticeable cpu overhead. -
Duplicate of https://devrant.com/rants/2378125/...
Please review the guidlines for asking questions.
Need help for a task
I need to do a code in JavaScript that decrements a user value, say 0.2>0.1>0.09>0.08 etc etc.
How do I decrement 0.1 to 0.09?
Thanks.
random
logic
javascript
problem
decimal