Java Code Examples for org.mozilla.javascript.v8dtoa.FastDtoa#numberToString()
The following examples show how to use
org.mozilla.javascript.v8dtoa.FastDtoa#numberToString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static String numberToString(double d, int base) { if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (d != d) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { // 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(); } }
Example 2
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static String numberToString(double d, int base) { if (d != d) return "NaN"; if (d == Double.POSITIVE_INFINITY) return "Infinity"; if (d == Double.NEGATIVE_INFINITY) return "-Infinity"; if (d == 0.0) return "0"; if ((base < 2) || (base > 36)) { throw Context.reportRuntimeError1( "msg.bad.radix", Integer.toString(base)); } if (base != 10) { return DToA.JS_dtobasestr(base, d); } else { // 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(); } }
Example 3
Source File: AbstractOperations.java From es6draft with MIT License | 5 votes |
private static String ToStringSlow(double value) { // call DToA for general number-to-string String result = FastDtoa.numberToString(value); if (result != null) { return result; } StringBuilder buffer = new StringBuilder(); DToA.JS_dtostr(buffer, DToA.DTOSTR_STANDARD, 0, value); return buffer.toString(); }