7 package com.google.appinventor.components.runtime.util;
9 import android.util.Log;
13 import java.util.Locale;
23 static final String LOG_TAG =
"YailNumberToString";
26 private static final double BIGBOUND = 1.e6;
28 private static final double SMALLBOUND = 1.e-6;
34 private static final String decPattern =
"#####0.0####";
36 private static final String sciPattern =
"0.####E0";
43 static Locale locale = Locale.US;
44 static DecimalFormatSymbols symbols =
new DecimalFormatSymbols(locale);
46 static DecimalFormat decimalFormat =
new DecimalFormat(decPattern, symbols);
47 static DecimalFormat sciFormat =
new DecimalFormat(sciPattern, symbols);
58 public static String
format(
double number) {
60 if (Double.isInfinite(number)) {
68 if (number == Math.rint(number)) {
69 return String.valueOf((
long) number);
71 double mag = Math.abs(number);
72 if (mag < BIGBOUND && mag > SMALLBOUND) {
73 return decimalFormat.format(number);
75 return sciFormat.format(number);