I would like to have calculated numbers automatically formatted, so that my pupils can easily read long numbers in my presentations. I figured out that `setupunits` combined with units, are quite convenient, but they work only if the digits are already formatted with points, and you can't pass a call to tex.print within this macro, as seen in this MWE

```
\setcharacterspacing[frenchpunctuation]
\mainlanguage[fr]
\language[fr]

\setupunits [method=3,order=reverse]

\starttext
\unit{1.000.333}

\unit{1000333}

{\directlua{tex.print(333*999)}}

\unit{\directlua{tex.print(333*999)}}

\stoptext

```

[![formatting output](https://i.stack.imgur.com/cOrb8.png)](https://i.stack.imgur.com/cOrb8.png)

What I would like is having a fourth line looking like 332 667 (eventually 332.667, which is also correct in French typography). 

After a quick search on the web, I found [this lua function](http://lua-users.org/wiki/FormattingNumbers) that could be assigned as a variable and then passed to `units`

```
function comma_value(n) -- credit http://richard.warburton.it
    local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
    return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end

```

The trouble is my lua skills are none. As far as I understand, such a function should be declared in a `\startluacode` `\stopluacode` environment, but even then I still have the issue that 

```
\unit{\directlua(comma_value(tex.print(333*999))}

```

does not have any output.

So,

* Is there a way to get this `unit`, `comma_value` and `tex.print` working together?
* How could I tweak the comma\_value function to have an French output, something like 332.667 instead of 333,667 (I understand `(num:reverse():gsub('(%d%d%d)','%1.')` should do the job for integers, but what if decimals are involved?)
* Last but not least, I suppose there is already a lua function doing the job in ConTeXt internal. Do you know it?