LimeReport Forum

General Category | Основное => Discussion | Обсуждение => Topic started by: JeremieBourque on March 18, 2024, 06:43:10 PM

Title: Strip trailing zeros from a number
Post by: JeremieBourque on March 18, 2024, 06:43:10 PM
Hello,

Thank you for creating LimeReport, it is very useful.

I was wondering if it is possible to format a number to a certain precision, but also strip the trailing zeros.

Examples with a precision of 4:

Thanks
Title: Re: Strip trailing zeros from a number
Post by: Subst on March 19, 2024, 03:59:45 PM
The "common" way to format as you want in the script using

Code: [Select]
$S{
  var value=1.000004;
  var approx=numberFormat(value,"f",4);
  while (approx.charAt(approx.length-1)=='0' || approx.charAt(approx.length-1)=='.')
    approx=approx.slice(0,-1);
  approx;
  }