How to round a float in F#?

System.Math.Round (3.21156,3);;
val it : float = 3.212

For reference, there are also built-in F# functions for floor, ceiling, truncate, and round; however, the built-in round function doesn't allow you to specify the precision like System.Math.Round(...) does.

Reference: http://msdn.microsoft.com/en-us/library/ee353754.aspx


good old multiply-divide by ten-to-the-power-of-the-precision-needed

round (3.21156 * 1000.) / 1000.
//3.212

Tags:

F#