A school assignment I'm working on says to format a decimal(14,0) column "as currency [US$xxx,xxx] and right justified [all the commas line up vertically]."
I can select the data in the correct format using this:
CONCAT("US$", FORMAT(theColumn, 0))
But the data is not right justified. I've been searching and searching and simply haven't been able to find any way to right justify the output.
I did find an answer on here that shows how to do it if the column is a string type and has a fixed width, but I can't find a way to right justify the output for a decimal data type. Is it possible?
EDIT:
MySQL returns data left justified, like this:
US$18,100,000,000
US$130,100,000,000
US$1,200,000,000
I want to select it right justified, like this:
US$18,100,000,000
US$130,100,000,000
US$1,200,000,000
I think you want
select lpad(column_name,x,' ') from table_name;
where x is the number of places you want that value you fill (so say 8 places)
I would have done:
LPAD(CONCAT("US$", FORMAT(theColumn, 0)),20,' ')
What this does is present the output in a column of 20 characters, padding ' ' to the left of values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With