Algosim documentation: SetNumDigits

SetNumDigits

Sets the number of digits formatting setting of a numeric entity.

Syntax

Description

SetNumDigits(x, n) returns x with its number of digits formatting setting set to n. n < 0 means that the default setting should be used.

If the “fixed” number format is used – which uses a fixed number of digits after the decimal separator – then the number of digits setting refers to this number of fractional digits. Otherwise, it refers to the number of significant digits.

For numbers, the \ operator can be used instead of the SetNumDigits function.

Notes

SetNumDigits should not be confused with SetMinLength, which can be used to pad integer values to a desired length by means of leading zeros.

Examples

π \ 5
3.1416	(=π)
π \ 18
3.14159265358979324	(=π)
1/69 \ 100
0.0144927536231884057971014492753623188405797101449275362318840579710144927536231
  8840579710144927536232	(=1/69)
SetNumDigits(SetNumberFormat(RandomMatrix(10, 5), "fixed"), 3)
⎛0.185  0.438  0.640  0.697  0.400⎞
⎜0.143  0.864  0.132  0.192  0.379⎟
⎜0.369  0.037  0.429  0.133  0.097⎟
⎜0.926  0.443  0.640  0.781  0.022⎟
⎜0.876  0.508  0.266  0.293  0.066⎟
⎜0.626  0.720  0.957  0.733  0.517⎟
⎜0.097  0.235  0.940  0.066  0.465⎟
⎜0.401  0.555  0.793  0.043  0.445⎟
⎜0.714  0.085  0.078  0.868  0.006⎟
⎝0.077  0.904  0.425  0.376  0.080⎠
x ≔ 1/123456789; r, c ≔ 10, 80;
join(flatten(group(characters(AsSingleLine(SetNumberFormat(x, "fixed") \ c⋅r−2)), c) @ (x ↦ x ~ '(chr(13), chr(10)))), "")  \ 100000
0.000000008100000073710000670761006103925155545718915466042130740983389742948846
66083450461359399198370532705171847617063813315280701169054380638394863809393260
66547867205585591570828883294542837980339825621092413151940959682662733112230871
32130092902383845411692993246406238542296770734900613687595584557119819469790357
17509225029333947766938924679144214580212352679932409387384925425202821369345674
46104563759551530211918924928462216849006173325956177266201213122431039414122458
66851437388348080233967530129104524174851169991145646919425386966771021397616294
71830828193660536562310882717029032724964197797174199954285219583995498214359033
75066720713107158489275142252403794496874529921558222286179822804236387518551126
41881525041121877874209088655302706763254631545617147065116038292555948462259131

See also