- [C#] Hướng dẫn viết ứng dụng theo dõi máy in bao nhiêu trang (Monitor Printer)
- [C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
- [C#] Chia sẽ class Install, Uninstall, Start và Stop Services Winform
- [C#] Tìm kiếm tập tin file nhanh chóng trên Winform sử dụng thư viện FastSearchLibrary
- [C#] Giới thiệu thư viện Fluent FTP Awesome dùng để làm việc với FTP
- [C#] Sử dụng thư viện Mini Profiler Integrations ghi log thực hiện các câu lệnh SQL
- [DEVEXPRESS] Thiết kế Dropdown ButtonBarItem trên Form Ribbon
- [C#] Lưu trạng thái các control trên Winform vào Registry Windows
- [C#] Ứng dụng ví dụ Simple Observer Pattern tăng giảm số lượng trên winform
- [C#] Hướng dẫn lấy thời gian thực server time trên winform
- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
Hướng dẫn đọc số thành chữ Việt Nam trong PHP
Hôm nay, mình xin chia sẽ cho các bạn đoạn code đổi số thành chữ Việt Nam trong PHP. Bạn có thể ứng dụng đoạn code đọc để đọc số tiền của Việt Nam, để xuất ra report cho đơn hàng...
Ví dụ: 15.000 => Mười lăm ngàn
315.258 => Ba trăm mười lăm ngàn hai trăm năm mươi tám.
function convert_number_to_words($number) {
$hyphen = ' ';
$conjunction = ' ';
$separator = ' ';
$negative = 'âm ';
$decimal = ' phẩy ';
$dictionary = array(
0 => 'không',
1 => 'một',
2 => 'hai',
3 => 'ba',
4 => 'bốn',
5 => 'năm',
6 => 'sáu',
7 => 'bảy',
8 => 'tám',
9 => 'chín',
10 => 'mười',
11 => 'mười một',
12 => 'mười hai',
13 => 'mười ba',
14 => 'mười bốn',
15 => 'mười năm',
16 => 'mười sáu',
17 => 'mười bảy',
18 => 'mười tám',
19 => 'mười chín',
20 => 'hai mươi',
30 => 'ba mươi',
40 => 'bốn mươi',
50 => 'năm mươi',
60 => 'sáu mươi',
70 => 'bảy mươi',
80 => 'tám mươi',
90 => 'chín mươi',
100 => 'trăm',
1000 => 'nghìn',
1000000 => 'triệu',
1000000000 => 'tỷ',
1000000000000 => 'nghìn tỷ',
1000000000000000 => 'nghìn triệu triệu',
1000000000000000000 => 'tỷ tỷ'
);
if (!is_numeric($number)) {
return false;
}
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
// overflow
trigger_error(
'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
E_USER_WARNING
);
return false;
}
if ($number < 0) {
return $negative . convert_number_to_words(abs($number));
}
$string = $fraction = null;
if (strpos($number, '.') !== false) {
list($number, $fraction) = explode('.', $number);
}
switch (true) {
case $number < 21:
$string = $dictionary[$number];
break;
case $number < 100:
$tens = ((int) ($number / 10)) * 10;
$units = $number % 10;
$string = $dictionary[$tens];
if ($units) {
$string .= $hyphen . $dictionary[$units];
}
break;
case $number < 1000:
$hundreds = $number / 100;
$remainder = $number % 100;
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
if ($remainder) {
$string .= $conjunction . $this->convert_number_to_words($remainder);
}
break;
default:
$baseUnit = pow(1000, floor(log($number, 1000)));
$numBaseUnits = (int) ($number / $baseUnit);
$remainder = $number % $baseUnit;
$string = $this->convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
if ($remainder) {
$string .= $remainder < 100 ? $conjunction : $separator;
$string .= $this->convert_number_to_words($remainder);
}
break;
}
if (null !== $fraction && is_numeric($fraction)) {
$string .= $decimal;
$words = array();
foreach (str_split((string) $fraction) as $number) {
$words[] = $dictionary[$number];
}
$string .= implode(' ', $words);
}
return $string;
}
- Đoạn code này cũng rất dễ hiểu các bạn có thể tùy biến theo ý của mình.
Chúc các bạn thành công!