I am utilizing a javascript function called tafgeet to convert numbers into Arabic words. However, the issue is that it only supports up to 2 decimal places. How can I adjust the function to handle 3 decimal places?
Currently, it translates numbers up to a million on the left side, so it should be feasible to apply a similar process on the right side.
I attempted to tweak the function but without success. Below is the original javascript code:
/**
* TafgeetJS module.
* @module TafgeetJS
* @description Converts currency digits into written Arabic words
* @author Mohammed Mahgoub <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d30303c353a32283f1d3a303c3431733e3230">[email protected]</a>>
*/
function Tafgeet(digit) {
var currency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "SDG";
//Split fractions
var splitted = digit.toString().split(".");
this.fraction = 0;
if (splitted.length > 1) {
var fraction = parseInt(splitted[1]);
if (fraction >= 1 && fraction <= 99) {
this.fraction = splitted[1].length === 1 ? fraction * 10 : fraction;
} else {
//trim it
var trimmed = Array.from(splitted[1]);
this.fraction = "" + trimmed[0] + trimmed[1];
}
}
this.digit = splitted[0];
this.currency = currency;
}
Tafgeet.prototype.parse = function () {
var serialized = [];
var tmp = [];
var inc = 1;
var count = this.length();
var column = this.getColumnIndex();
if (count >= 16) {
console.error("Number out of range!");
return;
}
//Separate the number into columns
Array.from(this.digit.toString()).reverse().forEach(function (d, i) {
tmp.push(d);
if (inc == 3) {
serialized.unshift(tmp);
tmp = [];
inc = 0;
}
if (inc == 0 && count - (i + 1) < 3 && count - (i + 1) != 0) {
serialized.unshift(tmp);
}
inc++;
});
// Rest of the JavaScript code...
module.exports = Tafgeet;
Thank you.