CodeDocu.com

React and HTML Javascript Output of a number

 

Problem:

German numbers are calculated incorrectly in javascript / html.

 

Solution:

If you read in javascript or react you eat numbers as a string into a react number of the type number, then usually the . Point and , comma incorrectly taken.

 

That's why I wrote the small conversion function

convert_german_to_number(string) number

 

When reading a German number as a string

 

let sumPunkteGesamtnumber  =this.convert_german_to_number(row[sFeld_Punkte_Gesamt + ".SUM"]);

 

 

 

   private  convert_german_to_number(sValue:string) : number   {

    //*convert german 3.015,67

    sValue=sValue.replace(".","");

    sValue=sValue.replace(",",".");

    return  parseFloat(sValue);   

  }

 

  private  convert_english_to_german(sValue:string) : string   {

    //*convert english 3015.67 to german 3015,67

    sValue=sValue.replace(".",",");

    //sValue=sValue.replace(",",".");

    return  sValue;   

  }

 

 

 

Issue English in German

When output, my java.number can be converted to German decimal numbers / fixed-point numbers with 2 digits by first converting

number.toFixed(2)

and then

string.replace(".",",")

 

Example output in Sharepoint/react (with java)

 

${ sumPunkteGesamt.toFixed(2).replace(".",",")}

 

 

 

 

Handle german number strings in English numbers

 

 

 

 

 

Log script..... previously, all expenses went wrong

 

Incorrect expenses previously

The number is 3013

 

${ (sumPunkteGesamt}

3.013

 

.toLocaleString("de-DE",{maximumFractionDigits:2,minimumFractionDigits:2}

 

 

 ${new Intl.NumberFormat('de-DE',{maximumFractionDigits:2}).format(sumPunkteGesamt}

3,01

 

 

${sumPunkteGesamt.toLocaleString("en-US",{minimumFractionDigits:2maximumFractionDigits:2})}

3.01

 

 

${sumPunkteGesamt.toLocaleString("en-US")}

3.013

 

 

${sumPunkteGesamt.toLocaleString("de-DE")}

3,013  ist falsch. Hier ist nur der Punkt vertauscht

 

 

 

${sumPunkteGesamt.toLocaleString}

 

Ausgabe 3.103


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel