Add values to Textview treatment

Asked

Viewed 69 times

0

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

  • I believe that there is no problem the fate of being Textview, remains text, logic is the same

1 answer

0


Use the class Decimalformat to format numeric values, with it you can set 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 class Numberformat, with it you can form percentages, coins, whole values etc., for example:

NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
String formatted = nf.format(12345.67);
textView.setText(formatted);
  • I’ll try here to see if I have the expected result

  • home when I put the method the value that my Textview returned was always 123456.67, it always returns what you have here: String Formatted = nf.format(12345.67);

  • @Romãogomes Which one did you use?

  • I used all two, all return me the value (12345.67)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.