Wednesday, 15 February 2012

java - Represent double as integer without regex -


I am developing a calculator for android double field Has been given the name result , which I had inserted in a TextView

if I say result = 20.0 It should be presented as 20 (without the point and a zero). If results = 20.0001 it should be displayed unchanged.

Now I do with regular expressions but I think this is not a good idea. Is there another way of representing the double without any point and a zero if the double is actually an integer (without a point after the point)?

Use (d% 1 == 0) { To check that your double is not a decimal part , then use intValue () integer to get the double method < / Code>

  class testDouble {public static zero main (string [] args) {double results = 20.001; If (result% 1 == 0) {System.out.println (the result can be changed in "integer, there is no decimal part"); } Else {System.out.println (Results + "can not be converted into integer, decimal part is"); } Results = 20.000; If (result% 1 == 0) {System.out.println (the result can be changed in "integer, there is no decimal part"); Int intOfDouble = result.intValue (); System.out.println (The result can be converted into "integer + intOfDouble);}}}  

  in 20.001 integer Can not be changed, decimal part can change to 20.0 integer, no decimal part is changed to 20.0 integer 20  

No comments:

Post a Comment