1

im using TypeScript...

class calc{
    public example(input : number) : number{
        while(input >= 1){
            input--;
        }        
        return input;        
    }
}
let p = new clac;
console.log(p.example(3.1));

and output: 0.10000000000000009

Mahan
  • 11
  • 2
  • 3
    Just just found the wonders of floating point arithmetics. It's the same reason why [`0.1 + 0.2 != 0.3` in javascript (or most other languages)](https://techtalkbook.com/why-0-1-0-2-does-not-equal-0-3/#:~:text=In%20binary%2C%20decimal%20numbers%20cannot,uses%20binary%20floating%2Dpoint%20format.) – ShamPooSham Apr 06 '22 at 14:32
  • Please consider fixing the `clac` typo. – jcalz Apr 06 '22 at 15:35

1 Answers1

1

This is working as expected - the variable 3.1 is saved as a float, which saves numbers as rational fractions, and often approximates real numbers to do so