ansharma Posted February 23, 2011 Share Posted February 23, 2011 Hi every one, Here is the problem.. I have a string which looks like this '(243/433)*100' , i want to calculate its value, but dont know how to do. if i use type conversion then value becomes zero. Please help. Link to comment https://forums.phpfreaks.com/topic/228581-how-to-perform-calculation-on-string-datatype/ Share on other sites More sharing options...
trq Posted February 23, 2011 Share Posted February 23, 2011 eval. Link to comment https://forums.phpfreaks.com/topic/228581-how-to-perform-calculation-on-string-datatype/#findComment-1178563 Share on other sites More sharing options...
ansharma Posted February 23, 2011 Author Share Posted February 23, 2011 i want to calculate this. $n = '(243/433)*100'; Link to comment https://forums.phpfreaks.com/topic/228581-how-to-perform-calculation-on-string-datatype/#findComment-1178573 Share on other sites More sharing options...
mdgeus Posted February 23, 2011 Share Posted February 23, 2011 just remove the quotes $n = '(243/433)*100'; displays (243/433)*100 but $n = (243/433)*100; displays 56.120092378753 Link to comment https://forums.phpfreaks.com/topic/228581-how-to-perform-calculation-on-string-datatype/#findComment-1178620 Share on other sites More sharing options...
AbraCadaver Posted February 23, 2011 Share Posted February 23, 2011 i want to calculate this. $n = '(243/433)*100'; eval('$result = ' . $n . ';'); echo $result; //or $result = eval("return $n;"); echo $result; Link to comment https://forums.phpfreaks.com/topic/228581-how-to-perform-calculation-on-string-datatype/#findComment-1178707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.