38471-vm/includes/quantity_helper.php
2026-05-07 08:08:50 +00:00

35 lines
714 B
PHP

<?php
// includes/quantity_helper.php
if (!function_exists('quantity_precision')) {
function quantity_precision(): int
{
return 2;
}
}
if (!function_exists('quantity_step')) {
function quantity_step(): string
{
return '0.01';
}
}
if (!function_exists('normalize_quantity')) {
function normalize_quantity($value): float
{
if ($value === null || $value === '') {
return 0.0;
}
return round((float)$value, quantity_precision());
}
}
if (!function_exists('format_quantity')) {
function format_quantity($value): string
{
return number_format(normalize_quantity($value), quantity_precision(), '.', '');
}
}