1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00
GPXSee/src/nicenum.cpp

35 lines
462 B
C++
Raw Normal View History

2016-01-14 00:37:51 +01:00
#include <cmath>
#include "nicenum.h"
double niceNum(double x, int round)
{
int expv;
double f;
double nf;
2016-02-07 18:27:50 +01:00
expv = (int)floor(log10(x));
2016-01-14 00:37:51 +01:00
f = x / pow(10.0, expv);
if (round) {
if (f < 1.5)
nf = 1.0;
else if (f < 3.0)
nf = 2.0;
else if (f < 7.0)
nf = 5.0;
else
nf = 10.0;
} else {
if (f <= 1.0)
nf = 1.0;
else if (f <= 2.0)
nf = 2.0;
else if (f <= 5.0)
nf = 5.0;
else
nf = 10.0;
}
return nf * pow(10.0, expv);
}