thefollower Posted December 10, 2007 Share Posted December 10, 2007 I have a line where by two variables have numbers but i can't put them together, how is this done? $Multiply = 0.000 $Input = 45; Then i want them two, to be put together so one variable will show the string as: 0.00045 Im not looking for maths here just a way to string them together.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 For starters, they are not strings. Quote Link to comment Share on other sites More sharing options...
tommyboy123x Posted December 10, 2007 Share Posted December 10, 2007 moreover, that just equals zero. To get .00045, you need to multiply 45 x .00001 if you just want to put the two variables together, just make sure there arent two decimal places either. $answer = $multiply.$input; also make sure your variables are all the same case, i.e. $Multiply isn't the same as $multiply Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 moreover, that just equals zero. Actually, it would equal 45. If they where string and you wanted to concatinate them.... <?php $Multiply = '0.000'; $Input = '45'; echo $Multiply.$Input; ?> Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 10, 2007 Author Share Posted December 10, 2007 For starters, they are not strings. php defaults to numeric? If so that is pain in the butt!!! tommyboy.. unfortionutely your idea didn't quite produce what i was hoping for.. $Multiply = 0.00; $Input = 6; Echo $Answer = $Multiply.$Input; The result gave : 06 Instead of 0.006 Hope you can help. Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 10, 2007 Author Share Posted December 10, 2007 <?php $Multiply = '0.000'; $Input = '45'; echo $Multiply.$Input; ?> How did you get that to work ? it just shows 45 on my screen :S rather than 0.00045 Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 10, 2007 Author Share Posted December 10, 2007 settype($Multiply, "string"); settype($StrengthInput, "string"); $Multiply = 0.00; $StrengthInput = 6; Echo $Answer = $Multiply.$StrengthInput; This echos 06 also and if i put set type after the $variables it still shows 06 rather than 0.006 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 10, 2007 Share Posted December 10, 2007 Try something like this: <?php $Multiply = number_format(0,2); echo $Multiply."<br>"; $StrengthInput = 6; $Answer = $Multiply.$StrengthInput; echo $Answer."<br>"; ?> Ken Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 It defaults to the type of value the variable equals. If you dont put "quotes" around the number, then it sets to a numeric type. If you put "quotes" around a number, it sets it to a string. For starters, they are not strings. php defaults to numeric? If so that is pain in the butt!!! Quote Link to comment Share on other sites More sharing options...
thefollower Posted December 10, 2007 Author Share Posted December 10, 2007 So how do you make sure a $_POST variable equals a string like: $Input = $_POST['inputbox']; ^ that should be string not numeric otherwise it wont allow me to do the string combining.. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 $Input = (string)$_POST['inputbox']; Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 Everything sent via $_POST or $_GET is considered a string. 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.