com.squarespace.template.expr.Formats Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of template-core Show documentation
Show all versions of template-core Show documentation
Squarespace template compiler
package com.squarespace.template.expr;
import com.squarespace.template.dtoa.DToA;
import com.squarespace.template.v8dtoa.FastDtoa;
/**
* Miscellaneous formatting and parsing functions.
*/
public class Formats {
private Formats() { }
public static String number(double d) {
if (Double.isNaN(d))
return "NaN";
if (d == Double.POSITIVE_INFINITY)
return "Infinity";
if (d == Double.NEGATIVE_INFINITY)
return "-Infinity";
if (d == 0.0)
return "0";
// V8 FastDtoa can't convert all numbers, so try it first but
// fall back to old DToA in case it fails
String result = FastDtoa.numberToString(d);
if (result != null) {
return result;
}
StringBuilder buffer = new StringBuilder();
DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, d);
return buffer.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy