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.. Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/ Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 For starters, they are not strings. Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411274 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 Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411277 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; ?> Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411281 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. Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411289 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 Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411290 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 Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411350 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 Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411366 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!!! Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411378 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.. Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411406 Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 $Input = (string)$_POST['inputbox']; Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411411 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. Link to comment https://forums.phpfreaks.com/topic/81061-adding-string-variables/#findComment-411430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.