wright67uk Posted March 2, 2013 Share Posted March 2, 2013 How can I subtract from a variable, but keep my decimal places? When I try the below example I return 0 <?php $a = $_attributeSelection["backp1"]; echo $a -1; ?> // 1.53 becomes 0 However When I try the below example i return 0.69 <?php $b = 1.69; echo $b-1;?> // 1.69 becomes 0.69 Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 Sounds like your first variable is a string. Do a var_dump on it to see. You can cast it to a float if needed. Quote Link to comment Share on other sites More sharing options...
wright67uk Posted March 2, 2013 Author Share Posted March 2, 2013 Yes your right. Is floatval best used to do that? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2013 Share Posted March 2, 2013 Floatval() will not help with that field I'm looking to only return rows where the first two letters of $_attributeSelection["backp1"] are GB Quote Link to comment Share on other sites More sharing options...
wright67uk Posted March 2, 2013 Author Share Posted March 2, 2013 That was used in a different file. In this circumstance I'm only using numbers. That was amazingly well spotted however!!! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2013 Share Posted March 2, 2013 What does var_dump() give then? Quote Link to comment Share on other sites More sharing options...
wright67uk Posted March 2, 2013 Author Share Posted March 2, 2013 It says in using a string. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 3, 2013 Share Posted March 3, 2013 In that case you need to ... Quote Link to comment Share on other sites More sharing options...
wright67uk Posted March 3, 2013 Author Share Posted March 3, 2013 (edited) Look at the manual, and get confused about the difference between floatval, intval and settype lol. I could try one of these, until one works, but I dont want to cause any problems later down the line by using the wrong one Edited March 3, 2013 by wright67uk Quote Link to comment 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.