• 29-04-2022, 19:22:51
    #1
    Merhaba Sitede Ürün Fiyatı Yazınca Mesela 9600 Lira Fiyat Belirtiyorum Çıktı olarak

    9600.00 ₺ olarak gözüküyor Yardımcı olabilirmisiniz Ben yazdığım gibi gözükmesini istiyorum Kod Blogu aşağıda

    [PHPR]
    if ($aItem[ 'price' ] !== null) {
    $price = str_replace(array(osc_locale_thousands_sep(), osc_locale_dec_point()), array('', '.'), trim($aItem['price']));

    // update 440
    // $aItem[ 'price' ] = $price * 1000000;
    $comma_split = explode(',', (string)$price);
    if(is_array($comma_split) && count($comma_split) <= 2) { // only one comma
    $price = str_replace(',', '.', $price); // comma to decimal point
    } else {
    $price = str_replace(',', '', $price); // remove comma
    }

    $dot_split = explode('.', (string)$price);
    if(is_array($dot_split) && count($dot_split) > 2) { // more than one dot
    $decimal_part = end($dot_split);
    $integer_part = implode('', array_slice($dot_split, 0, -1));

    $price = $integer_part . '.' . $decimal_part;
    }

    $price = str_replace(' ', '', $price); // remove white spaces inside price
    if(is_numeric($price)) {
    $aItem['price'] = (float)$price * 1000000;
    } else {
    $aItem['price'] = $price; // will throw error on number validation
    }
    [/ PHPR]
  • 30-04-2022, 02:40:26
    #2
    Ufuk16 adlı üyeden alıntı: mesajı görüntüle
    Merhaba Sitede Ürün Fiyatı Yazınca Mesela 9600 Lira Fiyat Belirtiyorum Çıktı olarak

    9600.00 ₺ olarak gözüküyor Yardımcı olabilirmisiniz Ben yazdığım gibi gözükmesini istiyorum Kod Blogu aşağıda

    [PHPR]
    if ($aItem[ 'price' ] !== null) {
    $price = str_replace(array(osc_locale_thousands_sep(), osc_locale_dec_point()), array('', '.'), trim($aItem['price']));

    // update 440
    // $aItem[ 'price' ] = $price * 1000000;
    $comma_split = explode(',', (string)$price);
    if(is_array($comma_split) && count($comma_split) <= 2) { // only one comma
    $price = str_replace(',', '.', $price); // comma to decimal point
    } else {
    $price = str_replace(',', '', $price); // remove comma
    }

    $dot_split = explode('.', (string)$price);
    if(is_array($dot_split) && count($dot_split) > 2) { // more than one dot
    $decimal_part = end($dot_split);
    $integer_part = implode('', array_slice($dot_split, 0, -1));

    $price = $integer_part . '.' . $decimal_part;
    }

    $price = str_replace(' ', '', $price); // remove white spaces inside price
    if(is_numeric($price)) {
    $aItem['price'] = (float)$price * 1000000;
    } else {
    $aItem['price'] = $price; // will throw error on number validation
    }
    [/ PHPR]
    ondalık vb. kısımları işlemek için bu kadar emeğe ne gerek vardı number_format diye bir nimet mevcut neyse konuya gelecek olursak. Paylaştığınız üzerinden revize ettim. Yalnız kodlarınızda en üstteki if bloğu } ile kapatılmamış bende o yüzden kapatmadım. Paylaştığınız kısmı aşağıdaki ile değiştirip deneyebilirsiniz.

    if ($aItem[ 'price' ] !== null) {
    $price = trim($aItem['price']);