Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Insert comma in number? (http://www.velocityreviews.com/forums/t958473-re-insert-comma-in-number.html)

John Posner 03-07-2013 07:06 PM

Re: Insert comma in number?
 
Peter Otten wrote:

> Last not least there's the option to employ locale-aware formatting:



Not quite last ... there's the mind-bending regular expression route:

import re
re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "12345678") # 12,345,678
re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "-54321") # -54,321

-John





All times are GMT. The time now is 07:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.