Aligning single and double digit number with space in csv - excel

I have an excel-file that i need to save to a .csv or .txt to create a specific formatted file to a software I'm using. Two of the columns in the .csv or .txt contains data with single and double digit numbers. When saving excel-file to .csv or .txt these columns will be separated with the according separating value (semicolon, tab, aso.)
What I'm looking for is how to add a space in front of the single digit number so that it aligns to the right properly with the double digit number. I have tried to figure this out in the custom number formatting but I always end up with spaces both in front of the double digit and single digit.
To try and illustrate (left side is standard csv, right side is what I'm looking for):
;14;3; --> ;14; 3;
;12;22; --> ;12;22;
;13;5; --> ;13; 5;

The displayed format (cell number formatting) is exported as the CSV element value. Use a number format of [>9]0;_(0 to add a prefacing space to single digit values.
col1,col2,col3
AA, 2,2.00
BB, 3,3.00
CC, 4,4.00
DD, 5,5.00
EE, 6,6.00
FF, 7,7.00
GG, 8,8.00
HH, 9,9.00
II,10,10.00
JJ,11,11.00
KK,12,12.00
LL,13,13.00
MM,14,14.00
The middle field receive the custom number format.

Related

Pandas, why does division done to other rows lead to additional trailing zeroes on final row?

I have a table that shows participation in Hong Kong demonstrations by gender for different dates in 2019 (obtained from this source). The three first rows originally showed the percentage for males, females and unknown/unanswered. The final row shows the sample size. All data was initially of type string (the percentages included the % sign).
My DataFrame is titled gender_table
To be able to do some analysis, I first removed the percentage sign and changed the data to float type.
gender_table = gender_table.astype("float64")
This gives me the following:
To change the percentage values into ratios, I thought I'd just divide all the data (except the final row with sample size) by 100.
gender_table[:-1] = gender_table[:-1]/100
gender_table now looks like this:
My question is this: Why has this operation added additional trailing zeroes to the sample size row?
Pastebin with data (after removal of % signs) available here (can be saved as .csv and read into a Pandas df ("index_col=0")).
All rows of a column are formatted uniformly. The default format for a float variable x is f'{x:.6g}' (for details about format specifiers see here).
So when you divide the first rows that had 1 decimal place by 100 they get 3 decimal places and as all rows in a column share the same format 285.0 becomes 285.000.
This of course only changes the string representation of the values in the last row, the float values itself remain unchanged.

Why the value in csv file which less than thousand could not display 2 decimal places in excel but display in notepad++?

The csv file is generated by java program. The file I open notepad++, the values are in 2 decimal places as in the picture above shown. But when I open the file in excel, some values which less than thousand is not in 2 decimal places format.
Why it behaves like that?
Code is like.
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat formatter = new DecimalFormat("#,###.00", symbols);
fileWriter.append(String.valueOf(detailsContent.getAppliedAmount() == null ? "" : "\"" + formatter.format(new BigDecimal(detailsContent.getAppliedAmount()).setScale(2, BigDecimal.ROUND_DOWN)) + "\""));
fileWriter.append(String.valueOf(detailsContent.getAmountSaving() == null ? "" : "\"" + formatter.format(new BigDecimal(detailsContent.getAmountSaving()).setScale(2, BigDecimal.ROUND_DOWN)) + "\""));
With the numbers that are greater than 1000, Excel sees that the string from the CSV uses a thousand separator character, so it applies a number format to the cell. It takes its cue from the text, i.e. thousand separator and two decimals. If there were no thousand separator in the source, Excel would apply the General format.
With the smaller numbers, Excel applies the General format, which will omit zeros as decimals. The fact that the source file has two decimals is not a sufficient trigger for Excel to apply a specific number format.

Comma separated combination of LTR/RTL/Digit characters reorder issue

I have a comma separated list of values generated from an excel sheet. (Numbers and RTL Characters)
Having these values in columns: 1 | 2 | 3 | 4 | 5
would yield me the output of 1,2,3,4,5
But the issue arises when I have RTL characters (Persian/Arabic) in my columns: 1 2 ب الف and a 5 in the end.
Now the output becomes 1,2الف, ب, 5
Since my columns can have multiple sets of RTL characters it can really mess up the output to the point that it's no more trivial to fix it by substituting several inputs.
What are my options to produce a csv file with the right order?
Tools I used where javascript and excel and both had the same issue.
If your purpose is to only display the CSV for human eye, you can add ‏RIGHT-TO-LEFT MARK (‏) before each number:
‏1, ‏2, ب, الف, ‏5
‏1, ‏2, ب, الف, ‏5
Note that these characters may drive crazy any tool you use to parse the CSV.
I think your CSV file already has the right order. In the text you pasted in the question:
1,2الف, ب, 5
The "1" is the first character in the string, and the "5" is the last. It just doesn't seem that way to you because the first half of the string (1,2) is rendering LTR whereas the second half of the string (الف, ب, 5) is rendering RTL.

Excel Text Format Number to round to millions

Is there a way to imbed a number in a text string, while still rounding it to millions and showing an 'm'?
If it was just formatting, I would use:
#.#,, 'm'
and in text I would use:
text(ref, "#.#,,")
but how can you combine the two? the below does not work
text(ref, "#.#,,m")
=TEXT(ROUND(ref,-6)/1000000,"#,##0")&"m"
This would round a number up to millions and then replace the 6 0's with the letter 'm'. e.g. 4,658,458,685 would become:
4,658m
Edit:
The following works as requested with everything inside the TEXT function:
=TEXT(ref, "#.#,," & """m""")

remove only decimal place and not comma

Please i have 123,788.98, I want to remove the decimal place before storing in dbase so as to have just 123,789.
I tried round(123,789.98) but it gives me just 123.
Please how can remove the decimal place without removing the comma?
Divided with comma, these are two numbers. 123 and 788.98. So just round(788.98) and insert them both in one row.
INSERT INTO table(row) VALUES ('123,'.round(788.98).'')
If you have a comma, you can create two variables from the form input:
list($one, $two) = explode(",", "S_POST['amount']", 2);

Resources