Cómo mostrar dos dígitos después del punto decimal en SQL Server


Tengo una tabla que tiene una columna de float tipo de datos en SQL Server Quiero devolver mi valor de columna de tipo de datos float con 2 decimales.

For ex: if i insert 12.3, it should return 12.30

Si introduzco 12, debe devolver 12.00

Author: Rafael, 2013-11-21

3 answers

select cast(your_float_column as decimal(10,2))
from your_table

decimal(10,2) significa que puede tener un número decimal con una precisión total máxima de 10 dígitos. 2 de ellos después del punto decimal y 8 antes.

 81
Author: juergen d,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-11 23:56:46

También puedes usar el siguiente código que me ayuda:

select convert(numeric(10,2), column_name) as Total from TABLE_NAME

Donde Total es el alias del campo que desea.

 3
Author: Bha15,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-28 11:51:58

También puede hacer uso de lo Siguiente si desea Lanzar y Redondear también. Eso puede ayudarte a ti o a alguien más.

SELECT CAST(ROUND(Column_Name, 2) AS DECIMAL(10,2), Name FROM Table_Name
 0
Author: PatsonLeaner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-28 08:14:08