Get a precision using getFormat API call

Number formatting

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<p>
  Click the <b>Get Precision</b> button to output the number of decimal places
  to show after the decimal separator under the component.
</p>

<button onclick="getFormat()">Get precision</button>

<div id="pivot-container">The component will appear here</div>

<div class="output" id="output">Output will appear here</div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  height: 340,
  report: {
    "dataSource": {
      "filename": "data/data.csv"
    },
    "formats": [{
      "name": "",
      "decimalPlaces": 2
    }]
  }
});

function getFormat() {
  var format = pivot.getFormat();
  showOutput("Precision: " + format.decimalPlaces);
}

let outputInitialized = false;

function showOutput(content) {
  var log = "[" + (new Date()).toLocaleTimeString('en-US') + "] " + content;
  var outputElement = document.getElementById("output");
  if (!outputInitialized) {
    outputElement.innerText = '';
    outputInitialized = true;
  }
  outputElement.innerText += log + "\n";
  outputElement.scrollTop = outputElement.scrollHeight;
}