title: How do i change a number into fixed notation, like K, M, or B, in Javascript?
body: <p>I'm trying to change a number into a fixed notation, for example when the number is over 1000, change the number into x.x K, and so far everything i have tried has failed. You can see my code if you go to this link: <a href="https://jsfiddle.net/Blackcatgame77/vnzewfr1/7/" rel="nofollow noreferrer">https://jsfiddle.net/Blackcatgame77/vnzewfr1/7/</a>
  . I have a function ready to change my number into notation, here is the function</p>
  <pre><code>function formatter(cash) {
       if (cash &gt;= 1000000000) {
          return (cash / 1000000000).toFixed(1).replace(/\.0$/, '') + 'B';
       }
       if (cash &gt;= 1000000) {
          return (cash / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
       }
       if (cash &gt;= 1000) {
          return (cash / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
       }
  }
  </code></pre>
  <p>I'm not sure how to use this function to make the numbers change into notation when they reach 1000, 1000000, or 1000000000. Can someone tell me how i could do this?</p>