Simple Machines Community Forum

General Community => Scripting Help => Topic started by: mickjav on June 26, 2023, 07:43:39 AM

Title: Calculation Error
Post by: mickjav on June 26, 2023, 07:43:39 AM
I have been testing the below but keep getting 9 points when it should give 8  :(

$pledge_amount = 22.00

What this is designed for is to calculate points for posts and STShop, Although I may add a separate amount for posts in settings.

Current Settings
$modSettings['pledges_points_per_multiply_for'] = 10
$modSettings['pledges_points_per_multiply'] = 2
$modSettings['pledges_points_per'] = 2

/*
Add The posts And Shop Points If Installed
Devide The Amount By pledges_points_per_multiply_for
*/
//Make sure of whole number
$pledge_amount = (int) $pledge_amount;
if ($pledge_amount >= $modSettings['pledges_points_per_multiply_for'])
//if default amount is £10 and payment is £10 or £11 this will be 1, £20 will be 2
//Rounds Down
$pledge_for = (int) $pledge_amount / $modSettings['pledges_points_per_multiply_for'];
else
$pledge_for = 1;

$Points = $modSettings['pledges_points_per_multiply'] * $pledge_for;

$Points = $modSettings['pledges_points_per'] * $Points;
Title: Re: Calculation Error
Post by: GL700Wing on June 26, 2023, 07:59:15 AM
Quote from: mickjav on June 26, 2023, 07:43:39 AMI have been testing the below but keep getting 9 points when it should give 8  :(
My testing using your code gives an answer of 8.8 - if you only want the whole number change the last line to the following (ie, you need to use '(int)' with the bracketed calculation):
$Points = (int) ($modSettings['pledges_points_per'] * $Points);

Also, you don't need to use a second '(int) ' for '$pledge_amount' ...
Title: Re: Calculation Error
Post by: mickjav on June 26, 2023, 08:06:59 AM
Thanks Sorted, Can move on now  ;D