fix float formatting

calib-gui
Ondřej Hruška 2 years ago
parent b6ccfd7019
commit f23f726b2d
  1. 22
      Lib/snprintf/snprintf.c

@ -655,6 +655,8 @@ static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
int zpadlen = 0; int zpadlen = 0;
int caps = 0; int caps = 0;
int index; int index;
int fzeropad = 0;
int fzerocnt = 0;
double intpart; double intpart;
double fracpart; double fracpart;
double temp; double temp;
@ -728,6 +730,13 @@ static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
/* Convert fractional part */ /* Convert fractional part */
if (fracpart) { if (fracpart) {
// leading zeros in the fractional part
fzeropad = 0;
fzerocnt = max - 1;
while (fracpart < POW10(fzerocnt)) {
fzeropad++;
fzerocnt--;
}
do { do {
temp = fracpart; temp = fracpart;
my_modf(fracpart * 0.1, &fracpart); my_modf(fracpart * 0.1, &fracpart);
@ -785,8 +794,19 @@ static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
if (max > 0) { if (max > 0) {
dopr_outch(buffer, currlen, maxlen, '.'); dopr_outch(buffer, currlen, maxlen, '.');
while (fplace > 0) if (zpadlen > fzeropad) {
zpadlen -= fzeropad;
} else {
zpadlen = 0;
}
while (fzeropad-- > 0) {
dopr_outch(buffer, currlen, maxlen, '0');
}
while (fplace > 0) {
dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]); dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
}
} }
while (zpadlen > 0) { while (zpadlen > 0) {

Loading…
Cancel
Save