Frage

I am using Birt with Eclipse Indigo.

I am using a table in the report. The table will get values from the dataset. I want to convert the numbers to Persian numbers. I tried using java script but it doesn't work.

var number = dataSetRow["invoice-number"];
var farsiNumber=new Array();
farsiNumber[0]='\u06f0';
farsiNumber[1]='\u06f1';
farsiNumber[2]='\u06f2';
farsiNumber[3]='\u06f3';
farsiNumber[4]='\u06f4';
farsiNumber[5]='\u06f5';
farsiNumber[6]='\u06f6';
farsiNumber[7]='\u06f7';
farsiNumber[8]='\u06f8';
farsiNumber[9]='\u06f9';
var outputNumber = "";
for(var i=0;i<number.length;i++) {
var ch = number.charAt(i);
var index = farsiNumber[ch];
if(ch >= 0 && ch <= 9)
outputNumber = outputNumber+index;
else
outputNumber = outputNumber+ch;
}
this.data = outputNumber;

Is there any other way of doing it or should I create a plugin for the Birt Functions plugin to do this.

War es hilfreich?

Lösung

Use this JavaScript function to convert numbers to Persian:

function toPersianNumber(num){
  var persianNumberArray = new Array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹')
  var res = ''
  while(num/10 > 0){
    n = num%10
    num = parseInt(num/10)
    res = persianNumberArray[n] + res
  }
  return res
}

Andere Tipps

I'm using this function for a better performance :)

function toPersianChar(str) { var map = ["\u0660","\u0661","\u0662","\u0663","\u0664", "\u0665","\u0666","\u0667","\u0668","\u0669"] var replaceDigits = str.replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map[$0]});

return(replaceDigits);
};
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top