Reputation: 13
I want to convert decimal number to specific format.
FROM 123456789.1234 to 12,34,56,789.00.
I tried it using
SELECT FORMAT(123456789.1234, 'N', 'en-us') as 'en-us'
but this returns:
123,456,789.12
I also tried
SELECT FORMAT(123456789.1234, '##,###.00') as 'en-us'
and got the same result.
Any suggestions on this?
Upvotes: 1
Views: 384
Reputation: 50163
If, you don't want to use decimal values you could simply cast them as INT/BIGINT
SELECT FORMAT(cast(123456789.1234 as bigint), 'N', 'en-In')
Use culture parameter en-In
for Indian Numbering system instead of Western Numbering system en-us
look for Numbering system
Upvotes: 0
Reputation: 2032
Use ROUND
OR FLOOR
function with FORMAT
function -
SELECT FORMAT(ROUND(123456789.1234,0), 'N', 'en-IN') as 'Round',
FORMAT(FLOOR(123456789.1234), 'N', 'en-IN') as 'Floor'
Please check difference between Round
and Floor
function.
Upvotes: 1
Reputation: 1
Just try round() in inner side. you also want "12,34,56,789.00" format. So, for that you can change regional setting of your machine.
Upvotes: 0
Reputation: 468
The proper way to do this would probably be Round()
SELECT FORMAT(ROUND(123456789.1234,0), 'N', 'en-us') as 'en-us'
Upvotes: 0