liamloveslearning Posted May 24, 2011 Share Posted May 24, 2011 Hi all, Is it possible to store a percentage as a variable? say... var myvariable = 30%; I have a few variables which are going to multiplied by percentages, but im unsure how to do this and cant find much on Google... Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/ Share on other sites More sharing options...
KevinM1 Posted May 24, 2011 Share Posted May 24, 2011 A percentage is just a decimal. Store them as floats. Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219570 Share on other sites More sharing options...
liamloveslearning Posted May 24, 2011 Author Share Posted May 24, 2011 Thanks NightSlyr Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219572 Share on other sites More sharing options...
liamloveslearning Posted May 24, 2011 Author Share Posted May 24, 2011 Hope this isnt a stupid question, but to store them as floats is it simply a case of var myvariable = parseFloat(".27"); Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219577 Share on other sites More sharing options...
KevinM1 Posted May 24, 2011 Share Posted May 24, 2011 Why don't you try it and see if it works? Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219578 Share on other sites More sharing options...
ignace Posted May 24, 2011 Share Posted May 24, 2011 Why cast a string to a float while you can just write the float? var myvariable = .27; Quote Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219695 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.