python千位分隔符_python处理千分位分隔符有逗号,点号,空格等情况

更新时间:2023-07-13 00:17:15 阅读: 评论:0

产后多久可以用收腹带python千位分隔符_python处理千分位分隔符有逗号,点号,
空格等情况
哑舍结局
"""
from decimal import Decimal
def test():
result = ""
卧底游戏词语try:
# 计算公式:symbol_left + 格式化美元价 * value + symbol_right
# 公式参数说明:
# 格式化美元价: usaPrice的amount
最美的姿态# decimal_place: 是保留多少⼩数位
# dec_point: 是⼩数点符号
# thousands_p:是千位分割符号
# 获取格式化美元价
usa_price_amount = Decimal('59.24')
value = Decimal('160.234')
symbol_left = ' '
symbol_right = ""
动态美decimal_place = '2'
dec_point = '.'
thousands_p = ','
考普通话证calculate_decimal = usa_price_amount * value
# 保留⼏位⼩数
save_decimal_place_str = "%.{0}f".format(int(decimal_place)) % (
calculate_decimal)
# 逗号
comma_str = ","
# 点号
dot_str = "."
if thousands_p == comma_str and dec_point == dot_str:
thousands_p_comma_str = "{:,}".format(Decimal(save_decimal_place_str))
result = symbol_left + thousands_p_comma_str + symbol_right
el:
# 按照⽂档:由于⼩数点符号和千位分割符号,
# 会出现⼩数点符号是逗号,千位分割符号为点号
做梦梦到火灾# 所以对save_decimal_place_str进⾏拆分
# ⼩数点左边
split_result = save_decimal_place_str.split('.')
radix_point_left_str = split_result[0]
# ⼩数点右边
radix_point_right_str = ""
if 1 < len(split_result):
radix_point_right_str = save_decimal_place_str.split('.')[1]
# 千分位的分隔符以逗号作为基准
thousands_p_comma_str = "{:,}".format(
miss解说
Decimal(radix_point_left_str))
# 如果千分位的分隔符不是逗号
if thousands_p != comma_str:
radix_point_left_str = thousands_p_place(',', thousands_p)
el:
radix_point_left_str = thousands_p_comma_str
new_res = radix_point_left_str + dec_point + radix_point_right_str result = symbol_left + new_res + symbol_right
except Exception as e:
pass
return result
print(test())
"""

本文发布于:2023-07-13 00:17:15,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1079118.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:符号   逗号   分隔符   词语   说明   收腹   空格
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图