Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ public static String formatNumber(float number, int digitCount, boolean separate
* @param number
* @return
*/
public static float roundToNextSignificant(double number) {
if (Double.isInfinite(number) ||
Double.isNaN(number) ||
public static double roundToNextSignificant(double number) {
if (Double.isInfinite(number) ||
Double.isNaN(number) ||
number == 0.0)
return 0;
final float d = (float) Math.ceil((float) Math.log10(number < 0 ? -number : number));

final double d = Math.ceil(Math.log10(number < 0 ? -number : number));
final int pw = 1 - (int) d;
final float magnitude = (float) Math.pow(10, pw);
final double magnitude = Math.pow(10, pw);
final long shifted = Math.round(number * magnitude);
return shifted / magnitude;
}
Expand All @@ -374,11 +374,11 @@ public static float roundToNextSignificant(double number) {
*/
public static int getDecimals(float number) {

float i = roundToNextSignificant(number);
if (Float.isInfinite(i))
double i = roundToNextSignificant(number);

if (Double.isInfinite(i))
return 0;

return (int) Math.ceil(-Math.log10(i)) + 2;
}

Expand Down