Show sign or leave the space blank?

How can I show the sign of the Amount only if the amount is negative? Else just leave the space blank. I have a field type float64, which contains the Amount so is it possible if I can only show the sign if the Amount is Negative else leave the space blank.

For example, the Amount is -00008908.00 then show -00008908.00 else just show 00008908.00 and leave the place for the sign empty.

Something like this?
https://play.golang.org/p/3TI6P6ZNbCV

package main

import (
	"fmt"
	"math"
)

func main() {
	var test float64 = -1.0
	fmt.Println(Float2String(test))
	test = -0.1
	fmt.Println(Float2String(test))
	test = 1
	fmt.Println(Float2String(test))
	test = 0.1
	fmt.Println(Float2String(test))
}

func Float2String(xF float64) string {
	if math.Trunc(xF) == xF {
		return fmt.Sprintf("'% 09.0f'", xF)
	} else {
		return fmt.Sprintf("'% 09.2f'", xF)
	}
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.