Amit :
I have a string like "10.000" I just want 10 as integer how to do it in java?
I have done`
public static final Comparator<Product> By_PRICE = new Comparator<Product>() {
@Override
public int compare(Product o1, Product o2) {
//for name
// return o1.getName().compareTo(o2.getName());
// return o1.getFinalPrice().compareTo(o2.getFinalPrice());
return Integer.parseInt(o1.getFinalPrice()) > Integer.parseInt(o1.getFinalPrice()) ? -1
: (Integer.parseInt(o1.getFinalPrice()) < Integer.parseInt(o1.getFinalPrice())) ? 1 : 0;
// if (o1.getFinalPrice().compareTo(o2.getFinalPrice())>0){
// return 1;
// }
// else if (o1.getFinalPrice().compareTo(o2.getFinalPrice())<0){
// return -1;
// }
// else {
// return 0;
// }
}
};
` like this i want to use it for my recyclerview if I switch on it will sort my data which am getting from JSON as a string i tried almost everything but cannot find the answer i want to sort it if switch on then ascending and if switch off then descending order
shanbhagsv :
As per https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(float) use Math.round()
System.out.println(Math.round(Float.valueOf("10.000")))