weixin_39647787 2020-11-22 03:16
浏览 0

System.Decimal string.format issue

From on December 9, 2014 18:12

When I run the following program, I cannot format a System.Decimal. I have an integration with a .NET library that returns a decimal type that I need to display in the ironpython script.


import System
f = 1.42742
d = System.Decimal(f)
print "{}".format(d)            # 1.42742
print "{:,.2f}".format(f)       # 1.43
print "{:,.2f}".format(d * 1.0) # 1.43
print "{:,.2f}".format(d)       # 12f WRONG

Work Item Details

Original CodePlex Issue: Issue 34710 Status: Proposed Reason Closed: Unassigned Assigned to: Unassigned Reported on: Nov 30, 2013 at 1:34 PM Reported by: davcar Updated on: Dec 4, 2013 at 4:08 PM Updated by: jdhardy

Copied from original issue: IronLanguages/main#1093

该提问来源于开源项目:IronLanguages/ironpython2

  • 写回答

5条回答 默认 最新

  • weixin_39647787 2020-11-22 03:16
    关注

    From on December 9, 2014 18:12

    On 2013-12-03 01:51:36 UTC, jdhardy commented:

    Can you try converting to a decimal.Decimal first? d = decimal.Decimal(System.Decimal(f))

    Handling System.Decimal directly is preferable but this might at least give you a workaround.

    评论

报告相同问题?