Announcement

Collapse
No announcement yet.

Annoying Decimals

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annoying Decimals

    I am having trouble when I display certain values on my chart that have huge strings of decimal numbers. It happens with Russel (730.80000000000001), Gas, Oil, but not with FTSE or DAX, or DOW. Please see PICS below. I can not find and EFS function to strip off decimal places. Math. ROUND is not what I want since I do not want to round to the next interger.
    Attached Files

  • #2
    alexmihh
    You can use either the formatPriceNumber() function or the toFixed() method. See the respective links for the required syntax. For more information on the toFixed() method see this article in the Core JavaScript Guide
    Alex

    Comment


    • #3
      Perhaps this function will be helpful to you.
      We use it for formatting the prices on the currencies we trade but you should be able to adjust it as needed (just change the value of dmax). It even has error checking.

      It returns your passed value (fnum) as a properly formatted float:


      PHP Code:
      function fixFloat(fnum) {


          var 
      dmax 4;
          var 
      outnum;

          if (
      isNaN(fnum) || fnum == null) {
              return(
      null);
          } else {
              
      outnum fnum.toFixed(dmax);
              
      outnum parseFloat(outnum);
              return(
      outnum);
          }


      Good luck
      -t

      Comment


      • #4
        toFixed() wored

        Thanks. The .toFixed(n) stuff works like a charm

        Comment

        Working...
        X