1300,00 için 1,300.00 nasıl değiştirilir

3 Cevap php

Benim PHP çıkışlarında, sayı gösterir 1,234.56

Bunu nasıl 1234,56 veya 1.234,56 değiştirebilirsiniz?

Amerikan tarzı ve Avrupa yolu nedir?

Amerikan tarzı ile php çalışır mı?

3 Cevap

Kullan number_format:

echo number_format($num, 2, ',', '.');

Argümanlar olmak:

  1. Sayı kendisi
  2. Ondalık Puan miktarı
  3. Ondalık noktalarının ayırıcı
  4. Binlerce Ayırıcı

Avrupa yolu bölgesel değişir ve bunlardan biri olabilir:

  • 123.456,50 (örneğin Almanca)
  • 123,456.50 (örn. İngilizce)
  • 123 456,50 (örneğin Fransızca)
  • 123'456,50 (örn. İsviçre)

Amerikan yol 123,456.50 ve evet, tüm formatları çalışır. Onları nasıl çıktı farketmez, PHP 123456.50 biçiminde içten yüzer kolları.

Sen localeconv kullanarak yerelin biçim bilgilerini alabilirsiniz (http://php.net/localeconv):

<?php
if (false !== setlocale(LC_ALL, 'nl_NL.UTF-8@euro')) {
    $locale_info = localeconv();
    print_r($locale_info);
}
?>

Gibi bir şey verecektir:

Array
(
    [decimal_point] => .
    [thousands_sep] =>
    [int_curr_symbol] => EUR
    [currency_symbol] => €
    [mon_decimal_point] => ,
    [mon_thousands_sep] =>
    [positive_sign] =>
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 1
    [p_sep_by_space] => 1
    [n_cs_precedes] => 1
    [n_sep_by_space] => 1
    [p_sign_posn] => 1
    [n_sign_posn] => 2
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
            [0] => 3
            [1] => 3
        )

)

Why use Zend_Currency?

Zend_Currency para manipülasyonlar işlemek için aşağıdaki fonksiyonları sunar:

* Complete Locale support: Zend_Currency works with all available locales and therefore knows about over 100 different localized currencies. This includes currency names, abbreviations, money signs and more.
* Reusable Currency Definitions: Zend_Currency does not include the value of the currency. This is the reason why its functionality is not included in Zend_Locale_Format. Zend_Currency has the advantage that already defined currency representations can be reused.

* Fluent Interface: Zend_Currency includes fluent interfaces where possible.

* Additional Methods: Zend_Currency includes additional methods that offer information about which regions a currency is used in or which currency is used in a specified region.

 

// creates an instance with 'en_US' using 'USD', which is the default
// values for 'en_US'
$currency = new Zend_Currency('en_US');

// prints '$ 1,000.00'
echo $currency->toCurrency(1000);

Bu sadece uygun bir yerel bulmak zorunda, sizin için ne istedi tam olarak değil.