|Convert comma format Numbers in CSV data|
Convert numerals in csv
I am parsing some data and have a string of CSV with some numerals separated by comma.
Incase I split the csv based on the delimiter the numeral also gets affected.
String has data
companyName:ICICI Bank Limited,averagePrice:1,077.13,secDate:14NOV2013,series:EQ,
purpose:ANNUAL GENERAL MEETING\/DIVIDEND RS.20\/- PER SHARE,cm_adj_low_dt:28-AUG-13,
Where the values like 1,21,433.11 and 1,50,824 should be converted to regular numerals like 121433.11 then can use the string for further splitting.
Could you suggest any php based function or any technique to achieve the same.
[edited by: bill at 2:28 am (utc) on Nov 20, 2013]
[edit reason] fix code side-scroll [/edit]
Off the top of my head:
First use a Regular Expression to replace all occurrences of
and proceed from there. Do numerals ever occur at the beginning of a pattern? If not, all you need is
Not only do you have a problem with commas in numbers (that lucy24's suggestion should rather neatly solve) but there also appears to be a nested "data" array/object that itself contains commas relating to the fields in the nested object.
Just curious... whose/what number system formats their numbers in this way: "1,21,433.11" ?
I had a belated "Oops" as I realized that if numerals ever do occur at the beginning of a record, the Regular Expression I originally gave wouldn't be safe, because there are definitely numerals at the end of records. You would then have to look more closely at exactly what comes before or after
But if you don't have record-initial numerals, you are good to go.
|Just curious... whose/what number system formats their numbers in this way: "1,21,433.11" ? |
Those are lakhs. If numbers were bigger you might also see crores "12,34,56,789". I don't know what happens after you pass 10^9; I think it goes back to sets of three.
Edit: I looked it up. ICICI bank is, as expected, in India.
At least the data as given appears to consist of name:value pairs and the names do at least appear to follow common identifier convention, ie. don't start with a digit.
Ah, thanks for the enlightenment! (I actually have an account with ICICI bank(!), ... but in the UK!)
|I don't know what happens after you pass 10^9; I think it goes back to sets of three. |
It would seem to continue two by two, according to Wikipedia [en.wikipedia.org].
|whose/what number system formats their numbers in this way: "1,21,433.11" ? |
The Indian numbering system: [en.wikipedia.org...]