MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Fixed

Method Fixed

ext/formatting.go:282–311  ·  view source on GitHub ↗

Fixed implements formatStringInterpolator.Fixed.

(precision *int)

Source from the content-addressed store, hash-verified

280
281// Fixed implements formatStringInterpolator.Fixed.
282func (c *stringFormatter) Fixed(precision *int) func(ref.Val, string) (string, error) {
283 if precision == nil {
284 precision = new(int)
285 *precision = defaultPrecision
286 }
287 return func(arg ref.Val, locale string) (string, error) {
288 strException := false
289 if arg.Type() == types.StringType {
290 argStr := arg.Value().(string)
291 if argStr == "NaN" || argStr == "Infinity" || argStr == "-Infinity" {
292 strException = true
293 }
294 }
295 if arg.Type() != types.DoubleType && !strException {
296 return "", fixedPointFormatError(runtimeID, arg.Type().TypeName())
297 }
298 argFloatVal := arg.ConvertToType(types.DoubleType)
299 argFloat, ok := argFloatVal.Value().(float64)
300 if !ok {
301 return "", fmt.Errorf("could not convert \"%s\" to float64", argFloatVal.Value())
302 }
303 fmtStr := fmt.Sprintf("%%.%df", *precision)
304
305 matchedLocale, err := matchLanguage(locale)
306 if err != nil {
307 return "", fmt.Errorf("error matching locale: %w", err)
308 }
309 return message.NewPrinter(matchedLocale).Sprintf(fmtStr, argFloat), nil
310 }
311}
312
313// Scientific implements formatStringInterpolator.Scientific.
314func (c *stringFormatter) Scientific(precision *int) func(ref.Val, string) (string, error) {

Callers

nothing calls this directly

Calls 6

fixedPointFormatErrorFunction · 0.85
matchLanguageFunction · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65
ConvertToTypeMethod · 0.65

Tested by

no test coverage detected