0

i am getting double values,i need to reduce to approximative value after . for example

i have 123.678,i need to format this as 124.

if i have 123.212 i need to format this as 123

how can i done this,can any one please help me.

Thank u in advance.

laxmanperamalla
  • 551
  • 2
  • 5
  • 15

1 Answers1

1

Sounds like you want Math.round() for floats or Math.round() for doubles

public static int round(float a)

public static long round(double a)

Returns the closest int/long to the argument.

The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int/long.

In other words, the result is equal to the value of the expression: (int)Math.floor(a + 0.5f) or (long)Math.floor(a + 0.5d)

Community
  • 1
  • 1
typo.pl
  • 8,812
  • 2
  • 28
  • 29
  • Seriously? `double d = 123.678d; long n = Math.round(d);` – typo.pl Apr 02 '11 at 06:35
  • when i click on calculate button it displays result when it's position is portrait if i change the orientation then it will disappear it's value how i will handle to ovecome this problem. t mean the value should be appear when orientation changes also kindly help me anyone to quesions in android – laxmanperamalla Apr 11 '11 at 07:48
  • this is not related u can follow separate question tag – Narasimha Apr 11 '11 at 08:54
  • hi all how android code for write asynchronous class to display elements one by one help me anyone – laxmanperamalla Apr 12 '11 at 05:23