コード例 #1
0
func Test_ToCurrency(t *testing.T) {

	for _, test := range testsNTC {
		ntc := gonumbers.ToCurrency()

		if test.addPrecision {
			ntc.Options(gonumbers.Precision(test.precision))
		}

		if test.addUnit {
			ntc.Options(gonumbers.Unit(test.unit))
		}

		if test.addSeparator {
			ntc.Options(gonumbers.Separator(test.separator))
		}

		if test.addDelimiter {
			ntc.Options(gonumbers.Delimiter(test.delimiter))
		}

		assert(t, test.out, ntc.Perform(test.in))
	}

}
コード例 #2
0
func ExampleToCurrency() {
	ntc1 := gonumbers.ToCurrency()
	res1 := ntc1.Perform(1234567890.50)
	fmt.Println(res1)

	ntc2 := gonumbers.ToCurrency()
	ntc2.Options(gonumbers.Precision(2))
	res2 := ntc2.Perform(1234567890.506)
	fmt.Println(res2)

	ntc3 := gonumbers.ToCurrency()
	ntc3.Options(gonumbers.Precision(2), gonumbers.Unit("$"), gonumbers.Separator("."))
	res3 := ntc3.Perform(1234567890)
	fmt.Println(res3)

	ntc4 := gonumbers.ToCurrency()
	ntc4.Options(gonumbers.Precision(3), gonumbers.Unit("CAD$"), gonumbers.Separator("."), gonumbers.Delimiter(","))
	res4 := ntc4.Perform(1234567890.506)
	fmt.Println(res4)

	ntc5 := gonumbers.ToCurrency()
	ntc5.Options(gonumbers.Precision(2), gonumbers.Separator("."), gonumbers.Delimiter(""))
	res5 := ntc5.Perform(1234567890.50)
	fmt.Println(res5)

	ntc6 := gonumbers.ToCurrency()
	ntc6.Options(gonumbers.Precision(2), gonumbers.Separator(","), gonumbers.Delimiter("."))
	res6 := ntc6.Perform(1234567890.506)
	fmt.Println(res6)

	// Output:
	// $1,234,567,890.50
	// $1,234,567,890.51
	// $1,234,567,890.00
	// CAD$1,234,567,890.506
	// $1234567890.50
	// $1.234.567.890,51
}