xnowandtheworldx Posted July 11, 2008 Share Posted July 11, 2008 I need to convert an integer to decimal..if no one can get it that's fine, i'm sure I can find another way, but any help would be nice... basically this is what I need. [psuedo] user inputs a number convert_to_decimal(number) number is converted to a decimal return number [/psuedo] now how would I go about doing this? Thank you for any help guys! Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/ Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 What do you mean? This? $int = 5; $new = (float) $int; What are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587800 Share on other sites More sharing options...
xnowandtheworldx Posted July 11, 2008 Author Share Posted July 11, 2008 Ah sorry, basically, I need to convert say...5 to .5 I was actually just coming back to say this haha. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587802 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Uhh...... $newnumber = $_POST['number'] / 10; O_O Simple math... Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587805 Share on other sites More sharing options...
.josh Posted July 11, 2008 Share Posted July 11, 2008 you need to be more specific. Like, give a before/after number example. I vaguely remember back in school "convert to a decimal" meant for instance, taking 12345 and making it 123.45 is that what you mean? edit: ah responses already posted. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587806 Share on other sites More sharing options...
xnowandtheworldx Posted July 11, 2008 Author Share Posted July 11, 2008 Yes...but if it's 100, 100 / 10 = 10. I need this for percentages, so the number that is submitted is the percent, so for instance, if a user inputs 60 it needs to be .60 for the multiplication. Tell me if i'm not making any since. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587807 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 You need a percentage? Well 5 is not .5 if you're making percentages. Please be specific. Thanks. $newnumber = $_POST['number'] / 100; That's a percentage. 123 would 1.23 which is correct. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587810 Share on other sites More sharing options...
.josh Posted July 11, 2008 Share Posted July 11, 2008 you pretty much do math the same way with code as you do with paper.... how would you convert 60 to .6 on paper? 60 / 100. I'm not trying to be mean, but this isn't a math forum, it's a programming forum... Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587815 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 And before you say that there's a math based programming board, that's for real math problems that need to be solved with code, not simple division. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587819 Share on other sites More sharing options...
.josh Posted July 11, 2008 Share Posted July 11, 2008 And before you say that there's a math based programming board, that's for real math problems that need to be solved with code, not simple division. haha QFT Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587820 Share on other sites More sharing options...
xnowandtheworldx Posted July 11, 2008 Author Share Posted July 11, 2008 haha of course! Man i'm an idiot...sometimes the simplest things seems so much harder than they are haha. Thank you for your help everyone! Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587825 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 And before you say that there's a math based programming board, that's for real math problems that need to be solved with code, not simple division. haha QFT I've never seen someone use QFT on a programming board. That just made my day. xD Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587831 Share on other sites More sharing options...
discomatt Posted July 11, 2008 Share Posted July 11, 2008 I think he wants a script like this <?php $someNum = 1234567; # Cheap hack $newNum = '.' . $someNum; echo $newNum; ?> Ahh the joys of PHP not caring about type Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587833 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Not if he's doing percentages... Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587835 Share on other sites More sharing options...
discomatt Posted July 11, 2008 Share Posted July 11, 2008 Ah, missed that part. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587836 Share on other sites More sharing options...
xnowandtheworldx Posted July 11, 2008 Author Share Posted July 11, 2008 Haha, thanks for all the help guys! I did try the '.' . $number; but it didn't work for me for some reason haha, but once again thanks for everyone that helped! It's greatly appreciated. Edit: Finally got the '.' . $number; working haha! Can't believe the first thing I tried actually works, been stressing over this for about an hour haha! But thanks ONCE againe. Quote Link to comment https://forums.phpfreaks.com/topic/114313-solved-converting-integer-to-decimal/#findComment-587838 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.