I have a function that calculates a price based off of square footage and a base price.
The price goes up 10% for every 500sqft after 2000sqft. Anything 2000sqft and below is 149.99.
The function is below...
checkPrice = () => {
debugger;
let base_price = 149.99;
if(this.state.propertySqft > 2000){
let overage = this.state.propertySqft - 2000;
let percentage = Math.floor(overage % 500) * 10;
base_price += base_price * percentage;
this.setState({ totalPrice: base_price });
}
}
the issue I am having, is the percentage comes up as '0' if the square footage is a round number, and the math.ceil(overage % 500) seems to not be working properly.
for example.... if i was to put in 5001 sqft, the price should be 149.99 * 60% which would be 239.98, but it comes up as 164.98 as the percentage only ends up being 10, instead of 60.
If i put in 5000 sqft, the percentage comes up as '0', which this is the case for any round number I enter as the square footage.
Does anyone have any idea what Im doing wrong here or why this is not working the way Im expecting it to?
Math.floor(overage / 500)...