Jump to content

Returning 2 digits in the following code


Go to solution Solved by Barand,

Recommended Posts


Below is some PHP code that looks at a DB and outputs a value within the user declared time and date period, via user recall using a web app attached to it. The code is rounding the numbers but I want it to include 2 of the decimal places. The original numbers in the DB have up to 5 decimal digits. This code is making them whole numbers. i would like to include the first 2 digits. I suspect the float should somehow be float(2) . Not sure how to do that.

 

thanks in advance

 

<?php

$sql = ";WITH TOTAL_FULL_ENERGY_SUM_BASE_WEEKDAY_SUMMER AS

(

SELECT cdate, datepart(hh, cdate) as trans_hour, datepart(mi, cdate) as trans_minute, comm_id,

max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, meter_multiplier

FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id]

where comm_id='$comm_id' and meter_multiplier is not null

group by comm_id, cdate, meter_multiplier

)

SELECT top 1 *, datepart(weekday, cdate) as trans_date_day,

datepart(month, cdate) as trans_date_month, datepart(hour, cdate) as trans_date_hour, DATEPART(minute, cdate) as trans_date_minute

FROM TOTAL_FULL_ENERGY_SUM_BASE_WEEKDAY_SUMMER

 

where datepart(weekday, cdate) IN ('2', '3', '4', '5', '6')

AND DATEPART(MONTH, cdate) IN ('5','6','7','8','9','10')

and cdate between '$base_date $base_start_time' and '$base_date $base_end_time'

 

ORDER BY totalUsage desc";

$query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ $sumUsageWKW += $row[totalUsage];}sqlsrv_free_stmt($query);?>

 

Edited by Butterbean

Well, I will try to fix my mistakes in posting on the next thread.  For now, I have 

 

max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, meter_multiplier

 

My problem is that I don't know how to manipulate FLOAT so that it gives me 2 decimals.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.