Hi…
In my process, I do some calculations. Then I register the results in an Anvil app_table.
rounding the the values to one decimal digit with:
app_tables.iniciojob.add_row(producto=str(j+1),M1=round(result_list[0][j][0],1),…
But when I display in a DataGrid, it writes very long numbers:
What should be the problem?
Regards
Hi @patricio.villa,
welcome to the very old problem of floating point number.
In short, due to the way computers do math, its impossible to represent certain numbers. Details can be found all over the internet: What Every Computer Scientist Should Know About Floating-Point Arithmetic
You will proboably want something like this whenever you display float numbers client side:
textbox1.text = f"{my_number:.1f}"
Greetings Mark
4 Likes
Thank you…
The only thing is that I use a Data Binding to populate:

I cannot write the format there, right?
Any other option?
If we could define in the database a number field with just one decimal as in other DB, it would be easier I think.
Regards
You can do the formatting in the data binding, you’d just want to disable write back. e.g.
f"{self.item['balance']:.1f}"
1 Like