@@ -134,6 +134,62 @@ u'Donnerstag, 5. M\xe4rz 1987 17:12'
134
134
135
135
For more format examples head over to the `babel `_ documentation.
136
136
137
+ Formatting Numbers
138
+ ----------------
139
+
140
+ To format numbers you can use the :func: `format_number `,
141
+ :func: `format_decimal `, :func: `format_currency `, :func: `format_percent ` and :func: `format_scientific `
142
+ functions.
143
+
144
+ To play with the date formatting from the console, you can use the
145
+ :meth: `~flask.Flask.test_request_context ` method:
146
+
147
+ >>> app.test_request_context().push()
148
+
149
+ Here are some examples:
150
+
151
+ >>> from flask_babel import format_number
152
+ >>> format_number(1099 )
153
+ '1,099'
154
+
155
+ >>> from flask_babel import format_decimal
156
+ >>> format_decimal(1.2346 )
157
+ u'1.235'
158
+
159
+ >>> from flask_babel import format_currency
160
+ >>> format_currency(1099.98 , ' USD' )
161
+ '$1,099.98'
162
+
163
+ >>> from flask_babel import format_percent
164
+ >>> format_percent(0.34 )
165
+ '34%'
166
+
167
+ >>> from flask_babel import format_scientific
168
+ >>> format_scientific(10000 )
169
+ '1E4'
170
+
171
+ And again with a different language:
172
+
173
+ >>> app.config[' BABEL_DEFAULT_LOCALE' ] = ' de'
174
+ >>> from flask_babel import refresh; refresh()
175
+
176
+ >>> format_number(1099 )
177
+ '1.099'
178
+
179
+ >>> format_decimal(1.2346 )
180
+ '1,235'
181
+
182
+ >>> format_currency(1099.98 , ' USD' )
183
+ '1.099,98\xa0$'
184
+
185
+ >>> format_percent(0.34 )
186
+ '34\xa0%'
187
+
188
+ >>> format_scientific(10000 )
189
+ '1E4'
190
+
191
+ For more format examples head over to the `babel `_ documentation.
192
+
137
193
Using Translations
138
194
------------------
139
195
@@ -276,6 +332,19 @@ Datetime Functions
276
332
277
333
.. autofunction :: format_timedelta
278
334
335
+ Number Functions
336
+ ``````````````````
337
+
338
+ .. autofunction :: format_number
339
+
340
+ .. autofunction :: format_decimal
341
+
342
+ .. autofunction :: format_currency
343
+
344
+ .. autofunction :: format_percent
345
+
346
+ .. autofunction :: format_scientific
347
+
279
348
Gettext Functions
280
349
`````````````````
281
350
0 commit comments