Add values to TextView treatment

0

I'm creating a financial control app, it's a college project, where it shows the value in the form I made a TextView to be clicked open a Dialog where I created a custom keyboard to put the value, when the user adds the value and click ok the value passes to TextView exactly as the user passed the value, what I want to do is treat this value, but I do not know how to handle this value since I have always worked with C # and I have now started android, ex: if the user add a value without a comma I want the string to be added, 00. if the user add a value ex: 15.5 I want to add after 5 + a 0.

    
asked by anonymous 19.05.2018 / 17:35

1 answer

0

Use the DecimalFormat class. to format numeric values, you can define a pattern and then format it, for example:

DecimalFormat df = new DecimalFormat("#,##0.00");
String formatted = df.format(12345.67);

textView.setText(formatted);

Another option is to use the NumberFormat , with it you can form percentages, currencies, integer values etc, for example:

NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
String formatted = nf.format(12345.67);
textView.setText(formatted);
    
19.05.2018 / 20:49