MCPcopy Create free account
hub / github.com/pquerna/ffjson / formatDigits

Function formatDigits

fflib/v1/internal/ftoa.go:191–224  ·  view source on GitHub ↗
(dst []byte, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte)

Source from the content-addressed store, hash-verified

189}
190
191func formatDigits(dst []byte, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte) []byte {
192 switch fmt {
193 case 'e', 'E':
194 return fmtE(dst, neg, digs, prec, fmt)
195 case 'f':
196 return fmtF(dst, neg, digs, prec)
197 case 'g', 'G':
198 // trailing fractional zeros in 'e' form will be trimmed.
199 eprec := prec
200 if eprec > digs.nd && digs.nd >= digs.dp {
201 eprec = digs.nd
202 }
203 // %e is used if the exponent from the conversion
204 // is less than -4 or greater than or equal to the precision.
205 // if precision was the shortest possible, use precision 6 for this decision.
206 if shortest {
207 eprec = 6
208 }
209 exp := digs.dp - 1
210 if exp < -4 || exp >= eprec {
211 if prec > digs.nd {
212 prec = digs.nd
213 }
214 return fmtE(dst, neg, digs, prec-1, fmt+'e'-'g')
215 }
216 if prec > digs.dp {
217 prec = digs.nd
218 }
219 return fmtF(dst, neg, digs, max(prec-digs.dp, 0))
220 }
221
222 // unknown format
223 return append(dst, '%', fmt)
224}
225
226// Round d (= mant * 2^exp) to the shortest number of digits
227// that will let the original floating point value be precisely

Callers 2

genericFtoaFunction · 0.70
bigFtoaFunction · 0.70

Calls 3

fmtEFunction · 0.70
fmtFFunction · 0.70
maxFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…