0

I'm getting price from server in this format 1299.0000 or 4399.000 how i will remove all zero after "." help me please how i will do that how to remove numbers after"." ???? im getting form server price value infloating number how i will remove all zero after "."

how to remove zero after decimal like 13400.0000 (remove last 4 zero)

or 2349.00 (remove last 2 zero)

remove all zero after "." how I do that?

static ArrayList<String> Category_price= new ArrayList<String>();
Category_price.add(object.getString("price"));

   holder.txtText3.setText("Price: "+Html.fromHtml(ProductList.Category_price.get(position)));

Thanks

user2931692
  • 17
  • 2
  • 8
  • Make it an int variable – Manishika Oct 31 '13 at 06:41
  • Convert it to the appropriate data-type. Use an `int/long` if no decimals are allowed and use a `double` if some decimal precision is allowed (just be aware of relative precision limits - as long as no [or carefully limited] math is performed along the value it should be "OK" to represent a price). Then, *when displaying* the data, use the correct format (to string) conversions to display the appropriate (possibly none) number of digits after the decimal. – user2864740 Oct 31 '13 at 06:41
  • (Of course you should *probably* design to the code to handle a case of data like `99.95` - damn sneaky way of making $100 seem like less.) – user2864740 Oct 31 '13 at 06:48
  • this works in c#, probably in android too? http://stackoverflow.com/a/7983459/93647 – Oleg Vazhnev Nov 20 '13 at 19:01

4 Answers4

2

convert it into integer type..............................................

oR

Split the string, use decimal point(.) as a spliter character.

OR

String val=Html.fromHtml(ProductList.Category_price.get(position));
String val1=val.substring(0,val.indexOf("."));  
holder.txtText3.setText("Price: "+val1);
Sino
  • 886
  • 7
  • 21
1

try this way..

    BigDecimal bd = new BigDecimal(23.086);
    BigDecimal bd1= new BigDecimal(0.000);    
    DecimalFormat df = new DecimalFormat("0.##");    
    System.out.println("bd value::"+ df.format(bd));
    System.out.println("bd1 value::"+ df.format(bd1));

Not only for Bigdecimal for decimal also..

kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
0

Try this

String[] separated = CurrentString.split(".");
separated[0]; // this will contain "price"
separated[1]; // this will contain " all your zeros"
Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23
0

Try this:

String price = object.getString("price");
String price = price.substring(0, price.indexOf("."));

If your string is always in that format (2 digits, minus, 2 digits, minus, 4 digits, space etc...) then you can use substring(int beginIndex, int endIndex) method of string to get what you want.

Note that second parameter is the index of character after returning substring.

Linga
  • 10,379
  • 10
  • 52
  • 104