SplitScript reference / Float / roundTo

Float.roundTo

Method

T.roundTo(decimalPlaces: u32) -> T where T: Float

Rounds to a requested number of digits after the decimal point.

Halfway values are rounded to even. If the decimal scale or scaled value cannot be represented finitely, the receiver is returned unchanged.

Parameters

  • decimalPlaces: The number of digits to preserve after the decimal point.

Effects: pure

Runtime behavior: available everywhere; synchronous

Examples

Keep two decimal places

let percentage = 0.7468.roundTo(2)