简体   繁体   中英

How to add formatting commas to a number in Google Refine

Due to what we're using the data for, it's important that long numbers (8+ digits) have commas every 3 digits for formatting and readability.

The issue is I really don't know how to make an expression that does this. Would anyone with some more experience writing these expressions point me in the right direction?

The supported expression languages are GREL (Google Refine Expression Language), Clojure, and Jython.

Using a substitution, this \\B(?=(\\d{3})+(?!\\d)) will insert a comma every three digits

So 12345678 becomes 12,345,678

It uses :

  • \\B : Negated word boundary, it's the negated version of \\b and matches at every position where \\b does not. Effectively, \\B matches at any position between two word characters as well as at any position between two non-word characters. More details

  • A positive look ahead (?=...) wich make sure the comma will be inserted every three digits starting from the right

Live DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM