June 24, 2011 at 6:22 am
Hi,
I need to format values on a report using commas , decimals, and a fixed dollar sign. So far, I have only been able to achieve a floating dollar sign. Can anyone provide the correct custom format mask? Thank you....
June 24, 2011 at 6:26 am
by fixed dollar sign, what do you mean? a dollar sign followed by a number up to say, $999,999,999.99 in size?
so 1.22 has 10 spaces between the $ and the one?
$999,999,999.99
$ 1.22
like that?
Lowell
June 24, 2011 at 6:59 am
You can use a function to reformat the data as a string.
The function could look like
create function MoneyToFixString(@InValue Money)
returns varchar(30)
as
begin
declare @TempValue varchar(30)
set @TempValue = CONVERT(varchar(30), @InValue, 1)
return '$' + substring(' ', 1, 29 - LEN(@TempValue)) + @TempValue
end
go
declare @test-2 money
set @test-2 = 12345678.1234
select dbo.MoneyToFixString(@Test)
The 29 is the max length (30) less the leader length (1 for $)
You can make the inside of the function do anything you want.
Hope this is helpful
June 24, 2011 at 7:05 am
don't forget more than one space in a row will not render in HTML by default, you have to replace with or CHAR(160)
Lowell
June 24, 2011 at 7:33 am
yes, that is exactly what they want. The dollar signs should all line up in the leftmost corner of the cell.
June 24, 2011 at 10:08 am
ppbedz (6/24/2011)
yes, that is exactly what they want. The dollar signs should all line up in the leftmost corner of the cell.
A kind of a sideways way to do this would be to add a column to the left of your money column and just put a $ in the column. You could add visibility constraints if you need. Format the money column as a number with 2 decimal places and comma separators for 1,000s.
June 24, 2011 at 10:24 am
Daniel Bowlin (6/24/2011)
A kind of a sideways way to do this would be to add a column to the left of your money column and just put a $ in the column. You could add visibility constraints if you need. Format the money column as a number with 2 decimal places and comma separators for 1,000s.
Was just about to say this. Easy, quick, no data modification, no messing with padding/trimming/& nbsp stuff.
Not sure if this is the "best" or "right" way to do it though.
I'd test it though to see if you like it.
June 27, 2011 at 7:06 am
I actually considered that idea too. Going to wait and see whether the report user "pushes" the issue. They plan to export to excel and could change the formating after the fact (but you know users)......
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply