Reputation: 7873
I have created this kind of float format for cells:
floating_point_bordered = workbook.add_format({'num_format': '#,##0', 'border': 1})
worksheet.write(f'G{row}', position.price, floating_point_bordered)
When I generate xlsx file the I got this following result:
However the real value of this float is:
How to force float cells to show their values if increased precision?
Upvotes: 1
Views: 8849
Reputation: 41554
XlsxWriter uses Excel's numeric formats so you should figure out the format you need in Excel first.
It is probably something like #,##0.00
. For example:
import xlsxwriter
workbook = xlsxwriter.Workbook("test.xlsx")
worksheet = workbook.add_worksheet()
price = 879.65421
floating_point_bordered = workbook.add_format({'num_format': '#,##0.00', 'border': 1})
worksheet.write(2, 1, price, floating_point_bordered)
workbook.close()
However, the numeric format needs to be in the US locale with "grouping/thousands" separator is "," and the "decimal" point is "." (dot). See this section of the XlsxWriter docs on Number Formats in different locales for more information.
Upvotes: 4