-2

I get miscellaneous decimal values from the API. They may look like this 123.45, 0.12345678.

The format rule which I cannot change is like this: 1. if value <0, then have 8 decimal places 2. if value >0, then have 2 decimal places

Now, I cannot align the number based on the decimal dot. No matter if I align center, left or right. I always get something like this (aligned right)

       123.45
   0.12345678
         1.23
1234.12345678

Ideally, I need alignment like this

 123.45
   0.12345678
   1.23
1234.12345678

Is there a solution to this problem?

sandalone
  • 41,141
  • 63
  • 222
  • 338
  • you add some whitespaces but you will need to check the largest number to see hown many spaces you will need - http://stackoverflow.com/questions/10862975/how-to-put-space-character-into-a-string-name-in-xml -- you may need to convert to string – Tasos Jan 22 '16 at 10:17
  • 1
    Just pad your string to the right using a space as the padding character. http://stackoverflow.com/questions/11612866/java-string-padding-with-spaces – Phantômaxx Jan 22 '16 at 10:57
  • 1
    @HrundiV.Bakshi We don't have `StringUtils` in Android, but it's a good lead. – sandalone Jan 22 '16 at 11:34

1 Answers1

2

You can achieve this by using two separate text view in layout. One for decimal value and second for other.

Ashish Rajvanshi
  • 466
  • 4
  • 15