Fixed implements formatStringInterpolatorV2.Fixed.
(precision int)
| 237 | |
| 238 | // Fixed implements formatStringInterpolatorV2.Fixed. |
| 239 | func (c *stringFormatterV2) Fixed(precision int) func(ref.Val) (string, error) { |
| 240 | return func(arg ref.Val) (string, error) { |
| 241 | fmtStr := fmt.Sprintf("%%.%df", precision) |
| 242 | switch arg.Type() { |
| 243 | case types.IntType: |
| 244 | argInt, ok := arg.Value().(int64) |
| 245 | if !ok { |
| 246 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType) |
| 247 | } |
| 248 | return fmt.Sprintf(fmtStr, float64(argInt)), nil |
| 249 | case types.UintType: |
| 250 | argUint, ok := arg.Value().(uint64) |
| 251 | if !ok { |
| 252 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType) |
| 253 | } |
| 254 | return fmt.Sprintf(fmtStr, float64(argUint)), nil |
| 255 | case types.DoubleType: |
| 256 | argDbl, ok := arg.Value().(float64) |
| 257 | if !ok { |
| 258 | return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.DoubleType) |
| 259 | } |
| 260 | if math.IsNaN(argDbl) { |
| 261 | return "NaN", nil |
| 262 | } |
| 263 | if math.IsInf(argDbl, -1) { |
| 264 | return "-Infinity", nil |
| 265 | } |
| 266 | if math.IsInf(argDbl, 1) { |
| 267 | return "Infinity", nil |
| 268 | } |
| 269 | return fmt.Sprintf(fmtStr, argDbl), nil |
| 270 | default: |
| 271 | return "", fixedPointFormatErrorV2(runtimeID, arg.Type().TypeName()) |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // Scientific implements formatStringInterpolatorV2.Scientific. |
| 277 | func (c *stringFormatterV2) Scientific(precision int) func(ref.Val) (string, error) { |
nothing calls this directly
no test coverage detected