PHP API Indexing Numbers (Prices) as Strings

I’ve implemented a sorting replica, but I see now that my prices are being uploaded as strings and not as numbers. Normally, if I controlled the json_encode feature, I’d add a JSON_NUMERIC_CHECK flag to the method. But I don’t.

How do I implement numbers instead of strings?

foreach ( $records as $record )
{
    $add[] = [
        'objectID' => $record['id'],
        'title' => $record['title'],
        'desc' => $record['desc'],
        'price' => [
            'final' => $record['price_sale'] ?? $record['price'],
            'regular' => $record['price'],
            'sale' => $record['price_sale']
        ]
    ];
}

$this->index->saveObjects($add);

It turns out you can force the numbers by casting them to a number (either int or float) and that json_encode will respect the type.

Example:

'regular' => (float) $record['price']