rakibhstu/number-to-bangla 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rakibhstu/number-to-bangla

Composer 安装命令:

composer require rakibhstu/number-to-bangla

包简介

A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.

README 文档

README

Packagist GitHub stars GitHub forks GitHub issues GitHub license Tests

Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format for Laravel 9.x, 10.x, 11.x, and 12.x.

Maximum possible number to convert in Bangla word is 999999999999999

Get Wordpress Plugin

Features

Operation English Input Bangla Output
Text (Integer) 13459 তেরো হাজার চার শত ঊনষাট
Text (Float) 1345.05 এক হাজার তিন শত পঁয়তাল্লিশ দশমিক শূন্য পাঁচ
Number 1345.5 ১৩৪৫.৫
Text Money Format 1345.50 এক হাজার তিন শত পঁয়তাল্লিশ টাকা পঞ্চাশ পয়সা
Month 12 ডিসেম্বর
Comma (Lakh) 121212121 ১২,১২,১২,১২১

Requirements

  • PHP 8.0 or higher
  • Laravel 9.x, 10.x, 11.x, or 12.x

Complete Usage Guide - NumberToBangla v2.0

🚀 Installation

composer require rakibhstu/number-to-bangla:^2.0

📖 Table of Contents

  1. Basic Number Conversion
  2. Date & Time
  3. Advanced Features
  4. Reverse Parsing
  5. Fluent API

Basic Number Conversion

Number to Bangla Digits

use Rakibhstu\Banglanumber\NumberToBangla;

$numto = new NumberToBangla();

echo $numto->bnNum(12345);
// Output: ১২৩৪৫

echo $numto->bnNum(1234.56);
// Output: ১২৩৪.৫৬

Number to Bangla Words

echo $numto->bnWord(12345);
// Output: বারো হাজার তিন শত পঁয়তাল্লিশ

echo $numto->bnWord(1345.05);
// Output: এক হাজার তিন শত পঁয়তাল্লিশ দশমিক শূন্য পাঁচ

Comma Separated (Lakh Format)

echo $numto->bnCommaLakh(1234567);
// Output: ১২,৩৪,৫৬৭

Percentage

echo $numto->bnPercentage(75.5);
// Output: ৭৫.৫%

echo $numto->bnPercentage(75.5, asWord: true);
// Output: পঁচাত্তর দশমিক পাঁচ শতাংশ

Currency Formatting

Money Format (Taka/Paisa)

echo $numto->bnMoney(5000);
// Output: পাঁচ হাজার টাকা

echo $numto->bnMoney(5000.50);
// Output: পাঁচ হাজার টাকা পঞ্চাশ পয়সা

Date & Time

Month Names

echo $numto->bnMonth(1);
// Output: জানুয়ারি

echo $numto->bnMonth(12);
// Output: ডিসেম্বর

Day Names

echo $numto->bnDay(1);
// Output: রবিবার

echo $numto->bnDay('monday');
// Output: সোমবার

Time Formatting

echo $numto->bnTime('14:30');
// Output: দুপুর ২:৩০

echo $numto->bnTime('14:30', asWord: true);
// Output: দুপুর দুইটা ত্রিশ মিনিট

echo $numto->bnTime('09:15', asWord: true);
// Output: সকাল নয়টা পনেরো মিনিট

Duration

echo $numto->bnDuration(3665);
// Output: ১ ঘন্টা ১ মিনিট ৫ সেকেন্ড

echo $numto->bnDuration(90);
// Output: ১ মিনিট ৩০ সেকেন্ড

Bengali Calendar

echo $numto->bnBengaliMonth(1);
// Output: বৈশাখ

echo $numto->bnSeason(1);
// Output: গ্রীষ্ম

echo $numto->bnSeason(5);
// Output: শীত

Age Calculator

echo $numto->bnAge('1990-01-15');
// Output: ৩৫ বছর

echo $numto->bnAge('1990-01-15', detailed: true);
// Output: ৩৫ বছর ২ মাস ৫ দিন

Date Formatting

echo $numto->bnDate('2024-01-15');
// Output: ১৫ জানুয়ারি, ২০২৪

---
## Reverse Parsing

### Parse Bangla Numbers to English
```php
$number = $numto->parseNum('১২৩৪৫');
// Output: 12345

$number = $numto->parseNum('১২,৩৪,৫৬৭');
// Output: 1234567

Fluent API

Beautiful Chaining

$result = $numto->number(12345)
                ->toBangla()
                ->asWord()
                ->withPrefix('মোট: ')
                ->withSuffix(' টাকা')
                ->get();
// Output: মোট: বারো হাজার তিন শত পঁয়তাল্লিশ টাকা

Different Formats

// As percentage
$result = $numto->number(75.5)
                ->asPercentage(asWord: true)
                ->get();
// Output: পঁচাত্তর দশমিক পাঁচ শতাংশ

Batch Processing

Convert Multiple Numbers

$numbers = [100, 200, 300];
$result = $numto->batch($numbers, 'bnNum');
// Output: ['১০০', '২০০', '৩০০']

$result = $numto->batch($numbers, 'bnWord');
// Output: ['এক শত', 'দুই শত', 'তিন শত']

With Associative Arrays

$data = [
    'revenue' => 500000,
    'expenses' => 200000,
    'profit' => 300000
];

$result = $numto->batchWithKeys($data, 'bnCurrency');
// Output: [
//   'revenue' => '৫ লক্ষ টাকা',
//   'expenses' => '২ লক্ষ টাকা',
//   'profit' => '৩ লক্ষ টাকা'
// ]

API Integration

Convert to Array

$result = $numto->toArray(12345);
/* Output:
[
    'original' => 12345,
    'bangla_number' => '১২৩৪৫',
    'bangla_word' => 'বারো হাজার তিন শত পঁয়তাল্লিশ',
    'money_format' => 'বারো হাজার তিন শত পঁয়তাল্লিশ টাকা',
    'comma_format' => '১২,৩৪৫'
]
*/

Convert to JSON

$json = $numto->toJson(12345);
// Returns UTF-8 encoded JSON string

In API Controllers

public function show($id)
{
    $product = Product::find($id);
    
    return response()->json([
        'name' => $product->name,
        'price' => NumberToBangla::convert($product->price),
        'price_words' => NumberToBangla::words($product->price),
        'discount' => [
            'rate' => app(NumberToBangla::class)->bnPercentage($product->discount),
            'amount' => NumberToBangla::money($product->discount_amount)
        ],
        'details' => app(NumberToBangla::class)->toArray($product->price)
    ]);
}

Static Helpers

Quick One-Liners

use Rakibhstu\Banglanumber\NumberToBangla;

// In controllers
$banglaNumber = NumberToBangla::convert(12345);

// In Blade
{{ NumberToBangla::words($amount) }}
{{ NumberToBangla::money($total) }}

// In models
public function getPriceAttribute($value)
{
    return NumberToBangla::convert($value);
}

Real-World Use Cases

E-Commerce

$discount = $numto->bnPercentage(20);
$final = $numto->bnMoney(20000);

// Stock display
$stock = $numto->bnWord(50) . ' পিস';

Education

$marks = $numto->bnNum(85);
$percentage = $numto->bnPercentage(85);

Official

// Official documents
$amount = $numto->bnMoney(50000);
$date = $numto->bnDate('2024-01-15');
$age = $numto->bnAge('1990-01-01');

Performance Tips

  1. Batch Processing: Use batch() for multiple conversions
  2. Static Helpers: Use for simple, one-off conversions
  3. Fluent API: Chain multiple operations efficiently

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email rakib1708@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Support

If you find this package helpful, please consider giving it a ⭐ on GitHub!

统计信息

  • 总下载量: 10.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 81
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 81
  • Watchers: 1
  • Forks: 36
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固