draw2dsvg/converters.go
func optiSprintf(format string, a ...interface{}) string {
	chunks := strings.Split(format, "%")
	newChunks := make([]string, len(chunks))
	for i, chunk := range chunks {
		if i != 0 {
			verb := chunk[0]
			if verb == 'f' || verb == 'F' {
				num := a[i-1].(float64)
				p := strconv.Itoa(getPrec(num, verb == 'F'))
				chunk = strings.Replace(chunk, string(verb), "."+p+"f", 1)
			}
		}
		newChunks[i] = chunk
	}
	format = strings.Join(newChunks, "%")
	return fmt.Sprintf(format, a...)
}
func optiSprintf(format string, a ...interface{}) string {
	chunks := strings.Split(format, "%")
	newChunks := make([]string, len(chunks))
	for i, chunk := range chunks {
		if i != 0 {
			verb := chunk[0]
			if verb == 'f' || verb == 'F' {
				num := a[i-1].(float64)
				p := strconv.Itoa(getPrec(num, verb == 'F'))
				chunk = strings.Replace(chunk, string(verb), "."+p+"f", 1)
			}
		}
		newChunks[i] = chunk
	}
	format = strings.Join(newChunks, "%")
	return fmt.Sprintf(format, a...)
}
// Do the same thing as fmt.Sprintf
// except it uses the optimal precition for floats: (0-3) for f and (0-6) for F
// eg.:
// optiSprintf("%f", 3.0)               => fmt.Sprintf("%.0f", 3.0)
// optiSprintf("%f", 3.33)              => fmt.Sprintf("%.2f", 3.33)
// optiSprintf("%f", 3.3001)            => fmt.Sprintf("%.1f", 3.3001)
// optiSprintf("%f", 3.333333333333333) => fmt.Sprintf("%.3f", 3.333333333333333)
// optiSprintf("%F", 3.333333333333333) => fmt.Sprintf("%.6f", 3.333333333333333)