How to ceil, floor and round bcmath numbers?

After a night lost trying to solve this problem I believe I’ve found a rather simple solution, here it is: function bcceil($number) { if (strpos($number, ‘.’) !== false) { if (preg_match(“~\.[0]+$~”, $number)) { return bcround($number, 0); } if ($number[0] != ‘-‘) { return bcadd($number, 1, 0); } return bcsub($number, 0, 0); } return $number; } … Read more

How to Round a Time in T-SQL

Try this function CREATE FUNCTION [dbo].[RoundTime] (@Time datetime, @RoundTo float) RETURNS datetime AS BEGIN DECLARE @RoundedTime smalldatetime DECLARE @Multiplier float SET @Multiplier= 24.0/@RoundTo SET @RoundedTime= ROUND(CAST(CAST(CONVERT(varchar,@Time,121) AS datetime) AS float) * @Multiplier,0)/@Multiplier RETURN @RoundedTime END select dbo.roundtime(’13:15′,0.5) The 1st param is the time to be rounded and the 2nd will be base on your list … Read more