String representation of self with the given number of decimals

assert 12.345.to_precision(0)    == "12"
assert 12.345.to_precision(3)    == "12.345"
assert (-12.345).to_precision(3) == "-12.345"
assert (-0.123).to_precision(3)  == "-0.123"
assert 0.999.to_precision(2)     == "1.00"
assert 0.999.to_precision(4)     == "0.9990"

Property definitions

core :: abstract_text $ Float :: to_precision
	# `String` representation of `self` with the given number of `decimals`
	#
	# ~~~
	# assert 12.345.to_precision(0)    == "12"
	# assert 12.345.to_precision(3)    == "12.345"
	# assert (-12.345).to_precision(3) == "-12.345"
	# assert (-0.123).to_precision(3)  == "-0.123"
	# assert 0.999.to_precision(2)     == "1.00"
	# assert 0.999.to_precision(4)     == "0.9990"
	# ~~~
	fun to_precision(decimals: Int): String
	do
		var is_inf_or_nan = check_inf_or_nan
		if is_inf_or_nan != null then return is_inf_or_nan
		return return_from_specific_format("%.{decimals}f".to_cstring)
	end
lib/core/text/abstract_text.nit:2104,2--2119,4