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. Quote 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. Quote 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'; Quote 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 Quote 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; Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.