Relating to this, and also tying into your title (“Or, how to turn content into numbers?”): don’t specify your data as content (i.e. with [ ]
) directly, only convert it to content when it’s fully processed. @ludwig’s suggestion was in the right direction: you’d specify your data as a float (which can be rounded), use oxifmt’s strfmt
function to round it to a certain amount of decimals, and only then you convert it to content (by just passing the final string to the table).
Their suggested num-table
function would only apply this to the second column, but it should be easy enough to generalize this to all floats (or even integers) you specify to the table, regardless of the table’s structure:
#import "@preview/oxifmt:0.2.1": strfmt
#let num-table(..args) = {
table(
..args.pos().map(n => {
if type(n) == float or type(n) == int {
// float(n) to ensure integers like '0' are also formatted
strfmt("{:.4}", float(n))
} else {
// Not a number, don't format
n
}
}),
..args.named()
)
}
#num-table(
columns: 3,
table.header([Thing], [number], [other]),
[a], 0.0100, 0.5,
[b], 0.0000, 0.6,
[c], -0.0050, 0.7,
[d], -0.0000, 0
)