sql - Convert fraction to decimal in Php -
this code
<?php id =$_get['id']; error_reporting(0); $con = mysql_connect("localhost","root",""); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("ehealth monitoring", $con); $sth = mysql_query("select dateandtime,bp table id='".$id."'"); $rows = array(); $rows['name'] = 'bp'; while($r = mysql_fetch_array($sth)) { $rows['data'][] = [$r['dateandtime'],$r[eval('bp')]]; } echo json_encode($rows, json_numeric_check); mysql_close($con); ?>
in code bp contains 100/77, 100/50, 99/45 kind of values. want convert values decimal. can't find mistake. please me convert values , pass value json.
this function you, feel free modify function per need.
<?php echo converttodecimal ("100/77"); function converttodecimal ($fraction) { $numbers=explode("/",$fraction); return round($numbers[0]/$numbers[1],6); } ?>
this function convert fraction decimal.
Comments
Post a Comment