Fix display for < 1 ETH values

This commit is contained in:
BTChip 2016-08-28 23:38:27 +02:00
parent ffd73c5c92
commit 34310ef17c
1 changed files with 8 additions and 7 deletions

View File

@ -218,17 +218,15 @@ bool adjustDecimals(char *src, uint32_t srcLength, char *target,
uint32_t startOffset;
uint32_t lastZeroOffset = 0;
uint32_t offset = 0;
if (srcLength == decimals) {
if (targetLength < srcLength + 1) {
if ((srcLength == 1) && (*src == '0')) {
if (targetLength < 2) {
return false;
}
for (uint32_t i = 0; i < srcLength; i++) {
target[i] = src[i];
}
target[srcLength] = '\0';
target[0] = '0';
target[1] = '\0';
return true;
}
if (srcLength < decimals) {
if (srcLength <= decimals) {
uint32_t delta = decimals - srcLength;
if (targetLength < srcLength + 1 + 2 + delta) {
return false;
@ -269,6 +267,9 @@ bool adjustDecimals(char *src, uint32_t srcLength, char *target,
}
if (lastZeroOffset != 0) {
target[lastZeroOffset] = '\0';
if (target[lastZeroOffset - 1] == '.') {
target[lastZeroOffset - 1] = '\0';
}
}
return true;
}