thombashi / pytablewriter

pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
https://pytablewriter.rtfd.io/
MIT License
610 stars 43 forks source link

Prevent formatting of float strings #53

Closed Nicholaswogan closed 2 years ago

Nicholaswogan commented 2 years ago
from pytablewriter import MarkdownTableWriter

writer = MarkdownTableWriter(
    headers=["bla"],
    value_matrix=[['1.e-10']])
writer.write_table()

results in

|    bla     |
|-----------:|
|0.0000000001|

How do you prevent this autmoatic formatting of '1.e-10'?? I want the output to be unformatted:

|    bla     |
|-----------:|
|1.e-10|

Docs should be adjusted so it is very clear how to prevent this automatic formatting.

thombashi commented 2 years ago

@Nicholaswogan You can prevent auto formatting by type_hints settings as follows:

from pytablewriter import MarkdownTableWriter

writer = MarkdownTableWriter(
    headers=["bla"],
    value_matrix=[['1.e-10']],
    type_hints=["String"],
)
writer.write_table()

outputs:

| bla  |
|------|
|1.e-10|

I will consider updating the documents.