You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求修改租车插件CRBSPrice类代码以移除ARS价格小数位

解决方案:移除阿根廷比索价格的小数位

根据你提供的CRBSPrice类代码,只需修改以下几处即可实现无小数位的价格显示与存储:

1. 修改前端价格格式化方法(numberFormat)

这个方法负责生成前端显示的价格格式,将小数位数从2改为0:

static function numberFormat($value,$currencyIndex)
{
    $Currency=new CRBSCurrency();
    $Validation=new CRBSValidation();
    
    $currency=$Currency->getCurrency($currencyIndex);
    
    if($Validation->isEmpty($value)) $value=0;
    
    // 直接设置小数位数为0,适配阿根廷比索无小数的需求
    $value=number_format($value,0,$currency['separator'],$currency['separator2']);
    return($value);
}

如果插件支持多货币,也可以通过判断货币代码仅针对ARS修改:

static function numberFormat($value,$currencyIndex)
{
    $Currency=new CRBSCurrency();
    $Validation=new CRBSValidation();
    
    $currency=$Currency->getCurrency($currencyIndex);
    
    if($Validation->isEmpty($value)) $value=0;
    
    // 仅对阿根廷比索(ARS)移除小数位,其他货币保留两位小数
    $decimalPlaces = ($currency['code'] === 'ARS') ? 0 : 2;
    $value=number_format($value,$decimalPlaces,$currency['separator'],$currency['separator2']);
    return($value);
}

2. 修改价格存储格式化方法(formatToSave)

这个方法处理存入数据库的价格格式,同样去掉小数位:

static function formatToSave($value,$empty=false)
{
    $Validation=new CRBSValidation();
    
    if(($Validation->isEmpty($value)) && ($empty)) return('');
    
    $value=preg_replace('/,/','.',$value);
    // 存储时直接保留整数
    $value=number_format($value,0,'.','');
    return($value);
}

3. 修正税费计算后的整数处理(calculateGross)

税费计算后可能产生小数,需要转换为整数确保一致性:

static function calculateGross($value,$taxRateId=0,$taxValue=0)
{
    if($taxRateId!=0)
    {
        $TaxRate=new CRBSTaxRate();
        $dictionary=$TaxRate->getDictionary();
        
        if(array_key_exists($taxRateId,$dictionary))
            $taxValue=(float)$dictionary[$taxRateId]['meta']['tax_rate_value'];
    }
    
    if(!is_numeric($value)) $value=0;
    if(!is_numeric($taxValue)) $taxValue=0;
    
    $value*=(1+($taxValue/100));
    
    // 将计算结果取整,确保无小数
    return (int)round($value);
}

修改完成后,插件输出的价格将从$1500.00变为$1500,完全符合阿根廷比索的使用习惯。

内容的提问来源于stack exchange,提问作者Pilar Puig Lómez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 11:54:14