Decimal implements formatStringInterpolatorV2.Decimal.
(arg ref.Val)
| 202 | |
| 203 | // Decimal implements formatStringInterpolatorV2.Decimal. |
| 204 | func (c *stringFormatterV2) Decimal(arg ref.Val) (string, error) { |
| 205 | switch arg.Type() { |
| 206 | case types.IntType: |
| 207 | argInt, ok := arg.Value().(int64) |
| 208 | if !ok { |
| 209 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType) |
| 210 | } |
| 211 | return strconv.FormatInt(argInt, 10), nil |
| 212 | case types.UintType: |
| 213 | argUint, ok := arg.Value().(uint64) |
| 214 | if !ok { |
| 215 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType) |
| 216 | } |
| 217 | return strconv.FormatUint(argUint, 10), nil |
| 218 | case types.DoubleType: |
| 219 | argDbl, ok := arg.Value().(float64) |
| 220 | if !ok { |
| 221 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.DoubleType) |
| 222 | } |
| 223 | if math.IsNaN(argDbl) { |
| 224 | return "NaN", nil |
| 225 | } |
| 226 | if math.IsInf(argDbl, -1) { |
| 227 | return "-Infinity", nil |
| 228 | } |
| 229 | if math.IsInf(argDbl, 1) { |
| 230 | return "Infinity", nil |
| 231 | } |
| 232 | return strconv.FormatFloat(argDbl, 'f', -1, 64), nil |
| 233 | default: |
| 234 | return "", decimalFormatErrorV2(runtimeID, arg.Type().TypeName()) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // Fixed implements formatStringInterpolatorV2.Fixed. |
| 239 | func (c *stringFormatterV2) Fixed(precision int) func(ref.Val) (string, error) { |
nothing calls this directly
no test coverage detected