In excel the function call “=round(12345,-3)” would resolve to “12000”. That is, the -3 rounding parameter allows the application of significant figures before the decimal point.
Does anyone know of an easy way (i.e. existing library call rather than a writing a custom divide/round/multiply function) to do this in f#?
Math.Round (12345, -3) fails because the second value in the tuple is required to be positive.
You can use the “G” standard format string to specify a number of significant digits. For example:
Obviously this gives you a string as the output. Maybe that’s what you were going to do with it anyway, or if not you can convert it back to a number with
Int32.Parse()or similar.There is also the answer to this question, which although in C# should be fairly simple to convert as it’s all .NET Framework method calls.