SetString sets d to s. Any non-standard NaN values are converted to a normal NaN. Any negative zero is converted to positive.
(s string)
| 487 | // SetString sets d to s. Any non-standard NaN values are converted to a |
| 488 | // normal NaN. Any negative zero is converted to positive. |
| 489 | func (d *DDecimal) SetString(s string) error { |
| 490 | // ExactCtx should be able to handle any decimal, but if there is any rounding |
| 491 | // or other inexact conversion, it will result in an error. |
| 492 | //_, res, err := HighPrecisionCtx.SetString(&d.Decimal, s) |
| 493 | _, res, err := ExactCtx.SetString(&d.Decimal, s) |
| 494 | if res != 0 || err != nil { |
| 495 | return makeParseError(s, types.Decimal, nil) |
| 496 | } |
| 497 | switch d.Form { |
| 498 | case apd.NaNSignaling: |
| 499 | d.Form = apd.NaN |
| 500 | d.Negative = false |
| 501 | case apd.NaN: |
| 502 | d.Negative = false |
| 503 | case apd.Finite: |
| 504 | if d.IsZero() && d.Negative { |
| 505 | d.Negative = false |
| 506 | } |
| 507 | } |
| 508 | return nil |
| 509 | } |
| 510 | |
| 511 | // ResolvedType implements the TypedExpr interface. |
| 512 | func (*DDecimal) ResolvedType() *types.T { |
no test coverage detected