Scientific implements formatStringInterpolator.Scientific.
(precision *int)
| 312 | |
| 313 | // Scientific implements formatStringInterpolator.Scientific. |
| 314 | func (c *stringFormatter) Scientific(precision *int) func(ref.Val, string) (string, error) { |
| 315 | if precision == nil { |
| 316 | precision = new(int) |
| 317 | *precision = defaultPrecision |
| 318 | } |
| 319 | return func(arg ref.Val, locale string) (string, error) { |
| 320 | strException := false |
| 321 | if arg.Type() == types.StringType { |
| 322 | argStr := arg.Value().(string) |
| 323 | if argStr == "NaN" || argStr == "Infinity" || argStr == "-Infinity" { |
| 324 | strException = true |
| 325 | } |
| 326 | } |
| 327 | if arg.Type() != types.DoubleType && !strException { |
| 328 | return "", scientificFormatError(runtimeID, arg.Type().TypeName()) |
| 329 | } |
| 330 | argFloatVal := arg.ConvertToType(types.DoubleType) |
| 331 | argFloat, ok := argFloatVal.Value().(float64) |
| 332 | if !ok { |
| 333 | return "", fmt.Errorf("could not convert \"%v\" to float64", argFloatVal.Value()) |
| 334 | } |
| 335 | matchedLocale, err := matchLanguage(locale) |
| 336 | if err != nil { |
| 337 | return "", fmt.Errorf("error matching locale: %w", err) |
| 338 | } |
| 339 | fmtStr := fmt.Sprintf("%%%de", *precision) |
| 340 | return message.NewPrinter(matchedLocale).Sprintf(fmtStr, argFloat), nil |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // Binary implements formatStringInterpolator.Binary. |
| 345 | func (c *stringFormatter) Binary(arg ref.Val, locale string) (string, error) { |
nothing calls this directly
no test coverage detected