Last updated:
0 purchases
num2persian
num2persian #
num2persian is a Dart library for converting numbers to their Persian word equivalents. This can be useful for displaying numbers in a more readable format in Persian-language applications, such as writing out monetary amounts in words.
Features #
Convert numbers to Persian words.
Convert numbers to Persian monetary units (Toman, Rial).
Format numbers with commas.
Convert numbers to Persian numerals.
Convert Rial to Toman and vice versa.
Support for both int and String types.
Installation #
Add the following dependency to your pubspec.yaml file:
dependencies:
num2persian: ^0.0.3
copied to clipboard
Then, run flutter pub get to fetch the package.
Usage #
To use the num2persian library, import it in your Dart code:
import 'package:num2persian/num2persian.dart';
copied to clipboard
Examples #
Convert Number to Persian Words
For String type:
String number = "123";
print(number.toPersianLetter()); // Output: یکصد و بیست و سه
copied to clipboard
For int type:
int number = 123;
print(number.toPersianLetter()); // Output: یکصد و بیست و سه
copied to clipboard
Convert Number to Persian Monetary Units
To Toman:
String number = "12345";
print(number.toToman()); // Output: دوازده هزار و سیصد و چهل و پنج تومان
copied to clipboard
To Rial:
int number = 12345;
print(number.toRial()); // Output: دوازده هزار و سیصد و چهل و پنج ریال
copied to clipboard
Format Number with Commas
For String type:
String number = "1234567";
print(number.formatWithCommas()); // Output: 1,234,567
copied to clipboard
For int type:
int number = 1234567;
print(number.formatWithCommas()); // Output: 1,234,567
copied to clipboard
Convert Number to Persian Numerals
For String type:
String number = "1234567";
print(number.toPersianNumber()); // Output: ۱۲۳۴۵۶۷
copied to clipboard
For int type:
int number = 1234567;
print(number.toPersianNumberInt()); // Output: ۱۲۳۴۵۶۷
copied to clipboard
Convert Rial to Toman
For String type:
String rial = "1234567";
print(rial.rialToToman()); // Output: 123456
copied to clipboard
For int type:
int rial = 1234567;
print(rial.rialToToman()); // Output: 123456
copied to clipboard
Convert Toman to Rial
For String type:
String toman = "123456";
print(toman.tomanToRial()); // Output: 1234560
copied to clipboard
For int type:
int toman = 123456;
print(toman.tomanToRial()); // Output: 1234560
copied to clipboard
Flutter Usage #
You can use num2persian in your Flutter applications to display numbers in Persian words within your UI components.
Example Flutter App #
Here's a simple example of a Flutter app using num2persian:
import 'package:flutter/material.dart';
import 'package:num2persian/num2persian.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('num2persian Example'),
),
body: Center(
child: NumberDisplay(),
),
),
);
}
}
class NumberDisplay extends StatelessWidget {
@override
Widget build(BuildContext context) {
String number = "123456";
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Number: $number'),
Text('In Persian: ${number.toPersianLetter()}'),
Text('As Toman: ${number.toToman()}'),
Text('As Rial: ${number.toRial()}'),
Text('With Commas: ${number.formatWithCommas()}'),
Text('In Persian Numerals: ${number.toPersianNumber()}'),
Text('Rial to Toman: ${number.rialToToman()}'),
Text('Toman to Rial: ${number.tomanToRial()}'),
],
);
}
}
copied to clipboard
This example creates a simple Flutter app with a NumberDisplay widget that shows the number in various formats using the num2persian library.
API #
num2persian #
String num2Persian(String number)
Converts a numeric string to its Persian word equivalent.
String number = "123";
print(num2Persian(number)); // Output: یکصد و بیست و سه
copied to clipboard
num2persian.PersianNumbers #
String toPersianLetter()
Converts the numeric string to its Persian word equivalent.
String number = "123";
print(number.toPersianLetter()); // Output: یکصد و بیست و سه
copied to clipboard
String toToman()
Converts the numeric string to Persian words followed by "تومان".
String number = "12345";
print(number.toToman()); // Output: دوازده هزار و سیصد و چهل و پنج تومان
copied to clipboard
String toRial()
Converts the numeric string to Persian words followed by "ریال".
String number = "12345";
print(number.toRial()); // Output: دوازده هزار و سیصد و چهل و پنج ریال
copied to clipboard
String formatWithCommas()
Formats the numeric string with commas.
String number = "1234567";
print(number.formatWithCommas()); // Output: 1,234,567
copied to clipboard
String toPersianNumber()
Converts the numeric string to Persian numerals.
String number = "1234567";
print(number.toPersianNumber()); // Output: ۱۲۳۴۵۶۷
copied to clipboard
Extensions on int #
String toPersianLetter()
Converts the integer to its Persian word equivalent.
int number = 123;
print(number.toPersianLetter()); // Output: یکصد و بیست و سه
copied to clipboard
String toToman()
Converts the integer to Persian words followed by "تومان".
int number = 12345;
print(number.toToman()); // Output: دوازده هزار و سیصد و چهل و پنج تومان
copied to clipboard
String toRial()
Converts the integer to Persian words followed by "ریال".
int number = 12345;
print(number.toRial()); // Output: دوازده هزار و سیصد و چهل و پنج ریال
copied to clipboard
String toPersianNumberInt()
Converts the integer to Persian numerals.
int number = 1234567;
print(number.toPersianNumberInt()); // Output: ۱۲۳۴۵۶۷
copied to clipboard
String formatWithCommas()
Formats the integer with commas.
int number = 1234567;
print(number.formatWithCommas()); // Output: 1,234,567
copied to clipboard
String rialToToman()
Converts the integer from Rial to Toman.
int rial = 1234567;
print(rial.rialToToman()); // Output: 123456
copied to clipboard
String tomanToRial()
Converts the integer from Toman to Rial.
int toman = 123456;
print(toman.tomanToRial()); // Output: 1234560
copied to clipboard
Contributing #
Contributions are welcome! Please submit a pull request or create an issue for any bugs or feature requests.
License #
This project is licensed under the Apache License. See the LICENSE file for details.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.