mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
make dec formatting consistent with f64
This commit is contained in:
parent
3560498106
commit
59af059912
@ -384,14 +384,19 @@ impl RocDec {
|
||||
// push a dummy character so we have space for the decimal dot
|
||||
string.push('$');
|
||||
|
||||
// Safety: at any time, the string only contains ascii characters, so it is always valid utf8
|
||||
let bytes = unsafe { string.as_bytes_mut() };
|
||||
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
|
||||
let bytes = unsafe { string.as_bytes_mut() };
|
||||
|
||||
// shift the fractional part by one
|
||||
bytes.copy_within(decimal_location..last_nonzero_byte, decimal_location + 1);
|
||||
// shift the fractional part by one
|
||||
bytes.copy_within(decimal_location..last_nonzero_byte, decimal_location + 1);
|
||||
|
||||
// and put in the decimal dot in the right place
|
||||
bytes[decimal_location] = b'.';
|
||||
// and put in the decimal dot in the right place
|
||||
bytes[decimal_location] = b'.';
|
||||
}
|
||||
|
||||
string.as_str()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user