patternsqlMinor
Float datatype with 2 digits after decimal point
Viewed 0 times
afterdatatypepointfloatdigitswithdecimal
Problem
In SQL server float datatype does not display trailing zeros after decimal point
will dispaly only
But i want it to display as
After a little research i found that it can be solved by using
But this is not the solution i am expecting. Is there any method like setting datatype or changing datatype so that i can achieve the same?(It will be better if any variants are there in float which can do the same)
If it is possible then i need not change the SQL statement and include cast etc. So please help me on this.
declare @num as float
set @num=5.20
select @numwill dispaly only
5.2But i want it to display as
5.20After a little research i found that it can be solved by using
select CAST(@num AS numeric(10,2))But this is not the solution i am expecting. Is there any method like setting datatype or changing datatype so that i can achieve the same?(It will be better if any variants are there in float which can do the same)
If it is possible then i need not change the SQL statement and include cast etc. So please help me on this.
Solution
This can be achieved with the
See below for an example:
The output here will be
After re-reading your question:
But this is not the solution i am expecting. Is there any method like setting datatype or changing datatype so that i can achieve the same?
Is there a reason why you are specifically using
decimal datatype.See below for an example:
declare @num as float;
set @num=5.20;
select convert(decimal(10, 2), @num);The output here will be
5.20.After re-reading your question:
But this is not the solution i am expecting. Is there any method like setting datatype or changing datatype so that i can achieve the same?
Is there a reason why you are specifically using
float? Oftentimes people tend to default to that datatype when decimal is more than sufficient.Code Snippets
declare @num as float;
set @num=5.20;
select convert(decimal(10, 2), @num);Context
StackExchange Database Administrators Q#56451, answer score: 9
Revisions (0)
No revisions yet.