make dec formatting consistent with f64

This commit is contained in:
Folkert 2023-09-11 20:21:51 +02:00
parent 3560498106
commit 59af059912
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -384,6 +384,10 @@ impl RocDec {
// push a dummy character so we have space for the decimal dot // push a dummy character so we have space for the decimal dot
string.push('$'); string.push('$');
if decimal_location == last_nonzero_byte {
// never have a '.' as the last character
string.truncate(last_nonzero_byte)
} else {
// Safety: at any time, the string only contains ascii characters, so it is always valid utf8 // Safety: at any time, the string only contains ascii characters, so it is always valid utf8
let bytes = unsafe { string.as_bytes_mut() }; let bytes = unsafe { string.as_bytes_mut() };
@ -392,6 +396,7 @@ impl RocDec {
// and put in the decimal dot in the right place // and put in the decimal dot in the right place
bytes[decimal_location] = b'.'; bytes[decimal_location] = b'.';
}
string.as_str() string.as_str()
} }