This Java library converts Persian numeric Price to Persian letter Price in two formats
This library can be utilized in any project that utilizes Java or Kotlin programming languages and supports both Maven and Gradle.
Add the jetpack repository to you'r project (pom.xml)
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add the dependency
<dependency>
<groupId>com.github.Rezakeshavarz1376</groupId>
<artifactId>PersianPriceTranslator</artifactId>
<version>latest-version</version>
</dependency>
Add it in your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.Rezakeshavarz1376:PersianPriceTranslator:latest-version'
}
To convert Persian numeric price to Persian letter price (translate PersianPrice to PersianPrice in Letter) , perform the following steps:
- Instantiate a new object of the PersianPriceTranslator class.
- Use the SetCurrencyUnit method to specify the currency unit.
- Use the setLetterPriceFormat method to set the output letter price format.
- If you do not set the currency unit and letter price format, the converter will use the default values of RIAL and FORMAT_LETTER_ONLY, in that order.
// instantiate object of class
PersianPriceTranslator persianPriceTranslator = new PersianPriceTranslator()
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.TOOMAN)
.setLetterCurrencyFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_NUMBER_AND_LETTER);
// call method for converting price
String priceInLetter = persianPriceTranslator.convertNumeralPriceToLetters("12345968752");
// instantiate object of class
val persianPriceTranslator = PersianPriceTranslator()
.setLetterPriceFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_LETTER_ONLY)
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.RIAL)
// call method for converting price
var priceInLetter = persianPriceTranslator.convertNumeralPriceToLetters(p0.toString())
Currency Unit | Description | input | output |
---|---|---|---|
CurrencyUnit.RIAL | you can choose this enum when you'r price parameter is Rial | 3242000 | سیصد و بیست و چهار هزار و دویست تومان |
CurrencyUnit.TOOMAN | you can choose this enum when you'r price parameter is Tooman | 324200 | سیصد و بیست و چهار هزار و دویست تومان |
LetterPriceFormat | Description | Input | output (persian) |
---|---|---|---|
FORMAT_LETTER_ONLY | you can use it when you want that output show you with Letter only | 324200 | سیصد و بیست و چهار هزار و دویست تومان |
FORMAT_NUMBER_AND_LETTER | you can use it when you want output show you number of price with number and other with letter | 324200 | 324 هزار و 200 تومان |
- This library supports prices ranging from 1 tooman to 999,999,999,999,999 tooman.
- The priceParameter in convertNumeralPriceToLetters function should only contain numbers.
PersianPriceTranslator persianPriceTranslator =new PersianPriceTranslator()
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.RIAL)
.setLetterPriceFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_LETTER_ONLY);
String priceLetter = persianPriceTranslator.convertNumeralPriceToLetters("324200");
سی و دو هزار و چهارصد و بیست تومان
PersianPriceTranslator persianPriceTranslator =new PersianPriceTranslator()
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.TOOMAN)
.setLetterPriceFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_LETTER_ONLY);
String priceLetter = persianPriceTranslator.convertNumeralPriceToLetters("324200");
سیصد و بیست و چهار هزار و دویست تومان
PersianPriceTranslator persianPriceTranslator =new PersianPriceTranslator()
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.RIAL)
.setLetterPriceFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_NUMBER_AND_LETTER);
String priceLetter = persianPriceTranslator.convertNumeralPriceToLetters("324200");
32 هزار و 420 تومان
PersianPriceTranslator persianPriceTranslator =new PersianPriceTranslator()
.setCurrencyUnit(PersianPriceTranslator.CurrencyUnit.TOOMAN)
.setLetterPriceFormat(PersianPriceTranslator.LetterPriceFormat.FORMAT_NUMBER_AND_LETTER);
String priceLetter = persianPriceTranslator.convertNumeralPriceToLetters("324200");
324 هزار و 200 تومان
There are two exceptions in this library
This exception is triggered when the input price parameter exceeds the range of values supported by the library.
This exception is triggered when the input price parameter contains invalid characters such as letters, spaces, or other non-numeric symbols, or when the input price parameter begins with a '0'