[GH-ISSUE #293] Writing a number in percent format #236

Closed
opened 2026-05-05 12:00:47 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @sapomuyverde on GitHub (Jun 1, 2020).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/293

Originally assigned to: @jmcnamara on GitHub.

Hi,
I receive data from sql and one of the columns comes in a percentage format something like 81.46% the data type is string.

If i write something like:
format_set_num_format (format1, "0.00%")
worksheet_write_number (worksheet, 10, 0, salesPercentage, format1)

I get this 8146.00%, Instead of what I expect, which is this 81.46%

On the other hand, if I treat the data as a string
worksheet_write_string (worksheet, 10, 0, salesPercentage, )

I display the correct data as I want in Excel, but with the warning number stored as text, which I want to avoid.

Any ideas how I could format percentage correctly.

Regards,
Javier

Originally created by @sapomuyverde on GitHub (Jun 1, 2020). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/293 Originally assigned to: @jmcnamara on GitHub. Hi, I receive data from sql and one of the columns comes in a percentage format something like 81.46% the data type is string. If i write something like: format_set_num_format (format1, "0.00%") worksheet_write_number (worksheet, 10, 0, salesPercentage, format1) I get this 8146.00%, Instead of what I expect, which is this 81.46% On the other hand, if I treat the data as a string worksheet_write_string (worksheet, 10, 0, salesPercentage, ) I display the correct data as I want in Excel, but with the warning number stored as text, which I want to avoid. Any ideas how I could format percentage correctly. Regards, Javier
gitea-mirror 2026-05-05 12:00:47 -06:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jmcnamara commented on GitHub (Jun 1, 2020):

In Excel percentages are divided by 100. You can verify that by creating a percentage in Excel and then converting it to a number.

So the same thing applies with Libxlsxwriter. You will need to divide the numbers by 100 and apply the number format.

<!-- gh-comment-id:637064332 --> @jmcnamara commented on GitHub (Jun 1, 2020): In Excel percentages are divided by 100. You can verify that by creating a percentage in Excel and then converting it to a number. So the same thing applies with Libxlsxwriter. You will need to divide the numbers by 100 and apply the number format.
Author
Owner

@sapomuyverde commented on GitHub (Jun 2, 2020):

Hi,
It works perfect, I appreciate your help.

Regards
Javier

<!-- gh-comment-id:637851443 --> @sapomuyverde commented on GitHub (Jun 2, 2020): Hi, It works perfect, I appreciate your help. Regards Javier
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#236
No description provided.