Web Hosting Talk







View Full Version : Java console - check specific characters with conditions.


horizon
11-25-2006, 09:02 PM
Hi,

I'm not quite the expert with Java consoles. I'm currently writing a class function that involve s verification of certain characters in my if statements. To clarify, I'd like to state on this function that if, as a decimal number (double), I have a '0' after the comma - eliminate it.

Ex: 12,0 - I'd like to eliminate the ',0' if zero is being returned after 12 (in this case).

Now, in case someone asks me to post this on, I did not code this part yet (since I don't know how to do it). That said, it would be greatly appreciated if someone (who does not favorize critism by the way. Otherwise, please don't reply) could give his input on this. :)

anlene
11-25-2006, 11:25 PM
Hi there,

Ref: http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
http://javaalmanac.com/egs/java.lang/HasSubstr.html?l=rel

horizon
11-26-2006, 08:23 AM
Thanks for those two posted links. The 2nd one looks more detailed than the first though.

However, this page seem to be what I'm looking for:

http://javaalmanac.com/egs/java.lang/HasSubstr.html?l=rel

Althought, if I take a look at this example:


// Ends with
b = string.matches("(?i).*adam");

Could I just state it like this:


// Ends with
b = double.matches("(?i).*,0.*");


for my case ?

If so, how can I specify if 'after the zero' value it's empty or not, since I only wish to remove the ',0' if there's no value after it. ;)

Saeven
11-26-2006, 06:07 PM
Do not get into regexps or string manipulation for simple things like this. Localization rules could cause your decimal format regexp or string explosion to fail anyways. Learn to use DecimalFormat instead, check the Java API.