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... 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. 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 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"); 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? 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; Link to comment https://forums.phpfreaks.com/topic/237335-store-percentage-as-variable/#findComment-1219695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.