Jump to content

[SOLVED] How to remove decimals in php (sql)?


Darla

Recommended Posts

Hello

 

I am wondering if there are any ways to remove extra decimals in php (or alternatively in sql)? I fetch aome average values from a table, and I wish to keep only one decimal or remove decimals entirely.

Ex:

14.6154 should be 14.6 og just 14.

 

Are there any "ready-to-use" functions for this in php/mysql?

 

Darla

Link to comment
https://forums.phpfreaks.com/topic/39038-solved-how-to-remove-decimals-in-php-sql/
Share on other sites

// mysql 14.6154 would become 14.6

 

SELECT ROUND(decimal_column, 1) AS rounded_number FROM ...;

 

// php

 

$number = 14.6154;

echo round ( $number, 1 ); // prints 14.6

 

dont include the second argument , 1 to return a rounded whole number (no decimal)

 

 

 

printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.