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

Method Decimal

ext/formatting_v2.go:204–236  ·  view source on GitHub ↗

Decimal implements formatStringInterpolatorV2.Decimal.

(arg ref.Val)

Source from the content-addressed store, hash-verified

202
203// Decimal implements formatStringInterpolatorV2.Decimal.
204func (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.
239func (c *stringFormatterV2) Fixed(precision int) func(ref.Val) (string, error) {

Callers

nothing calls this directly

Calls 4

decimalFormatErrorV2Function · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected