xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/strnum2.awk (revision e6d6c189fa3a95d7aa27bbe0aeacf7c1a6b57c8c)
1*e6d6c189SCody Peter MelloBEGIN {
2*e6d6c189SCody Peter Mello	split(" 1.234 ", f, "|")	# create a numeric string (strnum) value
3*e6d6c189SCody Peter Mello	OFMT = "%.1f"
4*e6d6c189SCody Peter Mello	CONVFMT = "%.2f"
5*e6d6c189SCody Peter Mello
6*e6d6c189SCody Peter Mello	# Check whether a strnum is displayed the same way before and
7*e6d6c189SCody Peter Mello	# after force_number is called. Also, should numeric strings
8*e6d6c189SCody Peter Mello	# be formatted with OFMT and CONVFMT or show the original string value?
9*e6d6c189SCody Peter Mello
10*e6d6c189SCody Peter Mello	print f[1]	# OFMT
11*e6d6c189SCody Peter Mello	print (f[1] "")	# CONVFMT
12*e6d6c189SCody Peter Mello
13*e6d6c189SCody Peter Mello	# force conversion to NUMBER if it has not happened already
14*e6d6c189SCody Peter Mello	x = f[1]+0
15*e6d6c189SCody Peter Mello
16*e6d6c189SCody Peter Mello	print f[1]	# OFMT
17*e6d6c189SCody Peter Mello	print (f[1] "")	# CONVFMT
18*e6d6c189SCody Peter Mello}
19