mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: improve float value display in export excel
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
from typing import List, Optional, Union, Dict, Any
|
||||
|
||||
import orjson
|
||||
@@ -207,7 +208,7 @@ def format_json_list_data(origin_data: list[dict]):
|
||||
value = str(value)
|
||||
# 小数且超过15位有效数字 → 转字符串并标记为文本列
|
||||
elif isinstance(value, float):
|
||||
decimal_str = format(value, '.16f').rstrip('0').rstrip('.')
|
||||
decimal_str = str(Decimal(str(value))).rstrip('0').rstrip('.')
|
||||
if len(decimal_str) > 15:
|
||||
value = str(value)
|
||||
_row[key] = value
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from decimal import Decimal
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from apps.chat.models.chat_model import AxisObj
|
||||
@@ -53,7 +55,7 @@ class DataFormat:
|
||||
"""格式化浮点数,避免科学记数法"""
|
||||
if value == 0:
|
||||
return "0"
|
||||
formatted = f"{value:.15f}"
|
||||
formatted = str(Decimal(str(value)))
|
||||
if '.' in formatted:
|
||||
formatted = formatted.rstrip('0').rstrip('.')
|
||||
return formatted
|
||||
|
||||
Reference in New Issue
Block a user