-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Round decimal place in Vector3 and CFrame when converting to dom type
- Loading branch information
1 parent
2e53cdc
commit bfcd78c
Showing
4 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// HACK: We round to the nearest Very Small Decimal | ||
// to reduce writing out floating point accumulation | ||
// errors to files (mostly relevant for xml formats) | ||
const ROUNDING: usize = 65_536; // 2 ^ 16 | ||
|
||
pub fn round_float_decimal(value: f32) -> f32 { | ||
let place = ROUNDING as f32; | ||
|
||
// Round only the fractional part, we do not want to | ||
// lose any float precision in case a user for some | ||
// reason has very very large float numbers in files | ||
let whole = value.trunc(); | ||
let fract = (value.fract() * place).round() / place; | ||
|
||
whole + fract | ||
} |