Closed FlorianJacta closed 1 year ago
Just came here searching for something similar. This is what I have:
<|{total_pred}|text|class_name=test|format=%,.0f|>
The value of total_pred
is 8075105.59837587
and it displays like this.
i.e. it rounds to 3 decimal places when I need it to be none. I might be doing something wrong in terms of the format string but open to comments.
I did notice that it works as it should when the raw number in question does not have a decimal component (i.e. is 45252.0
for example). If the decimal becomes non-zero, then it doesn't work.
I'm on Taipy 2.0.0.
I did a bit more fiddling and now it appears to work the other way (not sure what I changed specifically, but I now cast all my values as floats).
It seems to be linked to the type of value you pass to the text element - if it's an integer and you apply a number format, it doesn't seem to work properly, but if you cast the same value as a float and apply a number format then it works fine. To be fair the documentation mentions floating point values specifically, but I just expected there to be some exception handling that would work with integers.
This may not be related to the initial issue (since that is not an integer) so apologies if I hijacked it, just hoping my experience is useful in debugging.
Indeed <|{float(np.mean(data['values']))}|text|format=%.2f|> gives the expected result
Hi @Aazimh, the package used to format the value in the browser is sprinf-js. The format %,.0f is not valid for sprintf-js but %.0f works (I beleive you should have a warning in the browser console). The datatype is calculated at render from the value but int or float should be fine. The original question shows that we do not support (yet ?) numpy.float64 A quick workaround would be (as you discovered ?) to cast the result to a python float
Hey @FredLL-Avaiga - thanks for explaining what was going on, very interesting - I had no idea there was a material difference between a python float and numpy float :)
On the formatting, thank you for linking the library, I had spent a lot of time trying to find relevant documentation on what format placeholders to use. Strangely enough, the extra ,
I have in my format string works (it adds commas as thousand separators, which is what I was going for). So don't know if that's just a happy accident or maybe has been added to the library recently.
Thanks again for taking the time to add this context, appreciate it!
Description The format is not applied to the number for the text control.
How to reproduce
Expected behavior We should get 0.33 for the displayed number and not 0.3333333...
Runtime environment Please specify relevant indications.