2017-09-11 5 views
0

私は同じくらい XXXを示すために、一連の数値のセットをフォーマットしようとしています、XXX、XXX代わりの書式ロケール

値は、辞書、オーバーフォーマッタが繰り返さxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxのとのpythonでリスト。

これは、それがどのように見えるかです:

{'ST': [Decimal('21529992.247811'), 
Decimal('75922363.959394'), Decimal('1.688401841437798245794341100')], 
'LQT': [Decimal('23034058.811000'), Decimal('45706418.420000'), 
Decimal('0.243186493430996726476558100')], 'SR': 
[Decimal('8389288.802664'), Decimal('0393135.373964'), 
Decimal('-2.146515189191049793306943120')], 'MIS7': 
[Decimal('6382868.080000'), Decimal('5336228.320000'), 
Decimal('-4.879627090905261579809913330')], 'LQ': 
[Decimal('98508613.709000'), Decimal('38822011.125000'), 
Decimal('-3.983067033313078110002846960')] } 

これは私が持っている間違ってコーディングです:

import locale 
    locale.setlocale(locale.LC_ALL, '') 
    for k in result.keys(): 
     if result[k] == result[k]: 
      result[k] = locale.format('%d', result[k], grouping = True) 
    if len(result) == 0: 
     result["None"] = "None" 

私のエラー文字列が長いですが、これは主ビットのようになります。

TypeError: %d format: a number is required, not list 

何をする必要がありますか?

import locale 
    locale.setlocale(locale.LC_ALL, '') 
    for r in result: 
     for k in result[r]: 
      print locale.format('%2f', k, grouping = True) # Note there is not result[k]. Use your preferred number format instead of '%2f' 

、ここ'%2f'を使用して出力されます:ないだけではなぜ はあなたに

答えて

0

ありがとう

23.034.058,811000 
45.706.418,420000 
0,243186 
8.389.288,802664 
393.135,373964 
-2,146515 
6.382.868,080000 
5.336.228,320000 
-4,879627 
98.508.613,709000 
38.822.011,125000 
-3,983067 
21.529.992,247811 
75.922.363,959394 
1,688402 
+0

それを試してみました!ここに私のエラーがあります: "TypeError:%d形式:数値が必要です、strではありません" – ifthenifthen

+0

ここでうまく動作します。私のコードの変更に注意してください。 PS: 'result'はあなたの' dict'です。もちろん – floatingpurr

+0

@ifthenifthenが動作すれば教えてください。) – floatingpurr

関連する問題