unexpected number formatting
See original GitHub issueTitle: unexpected number formatting
Hi, I found unexpected number formatting when i use xlsxwriter
Here is some code that demonstrates the problem: Also you can check github repo with docker containers https://github.com/p0m1d0rka/xlsxwriter_weird_formatting
Xlsxwriter will add additional “\” before " " and “,” in excel and break format.
What am I doing wrong?
import xlsxwriter
import os
filename = 'xlsxwriter_test_python' + os.environ['PYTHON_VERSION'] + '.xlsx'
workbook = xlsxwriter.Workbook(filename)
worksheet = workbook.add_worksheet()
big_numbers_format = workbook.add_format({'num_format': '# ##0'})
percent_format = workbook.add_format({'num_format': '0,00%'})
#expected in excel 100 000 000, got 100000 000
worksheet.write_number (0, 0, 100000000, big_numbers_format)
#expected 99,99% in excel got 100%
worksheet.write_number (0, 1, 0.9999, percent_format)
workbook.close()
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
java - Unexpected number formatting in printed String - Stack Overflow
Unexpected number formatting in printed String · This has nothing to do with printf at all, just operator precedence and octal numbers. –...
Read more >[Solved]-unexpected number formatting output-C#
I assume you would need to build a custom numeric format string. value.ToString("#,0.##########", new CultureInfo("fr-CA")). The leading #,0 part introduces ...
Read more >Custom Number Format Show Unexpected Number When the ...
When using a custom number format, the negative numbers are shown as positive numbers. For example, when showing the numbers in Million, the...
Read more >number formatted is unexpected. - CodeRanch
I have a problem to make the number formatted to 2 points. This is the code i use and i expect to get...
Read more >Solved: Unexpected output of number format action for Germ...
Solved: Hello, I'm using the format number action as follows: My desired output based on the format would be "1.200,00" but it returns...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The reason this happens is that Excel stores the format in xlsx file in the US format (with “.” decimal and “,” thousand separator). When Excel reads and displays the file it uses the values set in Windows for the locale (“,” and " " in your case).
Thanks for the detailed report by the way. That is the first time anyone has supplied a docker image, even though the sample code was enough.
Thanks for that. It looks like your manual edits invoke the Excel builtin formats. See this section of the docs: “For backwards compatibility XlsxWriter also supports Excel’s built-in formats which are set via an index number, rather than a string” https://xlsxwriter.readthedocs.io/format.html#format-set-num-format
So the following should give you what you want (note the numbers instead of format strings:
The following may also work: