What I'm trying to accomplish, is that every time an amount gets updated to the uploaders 'balance' column,
half that amount gets updated(added to) into the uploaders 'money' column. However, using the code
below, when the amount '3' is added to the 'balance' column, just '1' gets added to the 'money' column,
instead of the intended amount of 1.5. And both columns have the same table structure:

$up_amount = $video_cost_new *0.50;


// add to the balance
$uploader_account = $up_user_start->balance+$up_amount;

$money_amount = $up_amount / 2;
$up_user_start = $db->where('id', $video->user_id)->getOne(T_USERS);
$money_account = $up_user_start->money+$money_amount;
$db->where('id', $video->user_id);
$update_money = $db->update(T_USERS, [
'money' => number_format($money_account, 1, '.', ''), ]);

Can you suggest what I can change to get it correct?

    Since number_format() returns a string, I'm not sure what will happen if you're trying to insert that into a float or decimal column type. Maybe use round() instead?

      PS: Is it in fact a float or decimal column? (E.g., if it's an integer type, you probably want to change that. 😉 )

        Much thanks for your reply.
        I copied the same structure from the 'balance' column, to create the 'money' column, and the 'balance' column updates and populates correctly. They are both varchar(100). Both are indexed.

        Regarding round(), if that rounds up the amount, I'm not sure how that would effect a result that is supposed to appear at times with an amount like this 10.5 for example

        Any afdditional ideas are welcomed.

        chrisj They are both varchar(100)

        Ugh. Why would it be a character column to track a numerical amount?

        But, that negates my concern about using number_format(). 🤷

          chrisj Regarding round(), if that rounds up the amount,

          It allows you to specify the precision in decimal places in its second argument.

            Many thanks again for your replies.
            Regarding ""Why would it be a character column to track a numerical amount?" what you suggest to be better?

            Additionally, I tried this, but still displayed a 1 in the money column, when it should have been 1.5.

            'money' => round($money_account, 2)]);

            any other help is appreciated

              I would store money values a DECIMAL type.

              As far as getting the actual value you want, it's hard to say just looking at that code, as I don't know what values are coming in (plus I don't know what your various class/object methods are doing). All I can suggest is some liberal use of error_log() and/or echo commands and such to find out what each variable of interest is actually set to, and what the result of each operation you do with them actually is, in order to narrow down where some value is not what you expect it to be.

              On a side note, if you use a decimal numeric type for that DB column, it will probably take care of the rounding for you, removing the need to do any rounding/formatting of the division result.

                Write a Reply...