jaggernat
asked on
validating a format xxx.xxxx
hi guys
I have a requirment where i have a decimal field 'rate' and rate
can be in format xxx or xxx.xxxx
for example rate can be 123 or 123.0000 or 123.3333. These are all valid rates
any idea how i can validate the rate in my java class
String rate = null;
if(rate is not in format xxx or xxx.xxxx)
{
//throw error
}
any idea, how i do this?
thanks
J
I have a requirment where i have a decimal field 'rate' and rate
can be in format xxx or xxx.xxxx
for example rate can be 123 or 123.0000 or 123.3333. These are all valid rates
any idea how i can validate the rate in my java class
String rate = null;
if(rate is not in format xxx or xxx.xxxx)
{
//throw error
}
any idea, how i do this?
thanks
J
ASKER
ok,thanks but i dint completely understand
>>>Number x = new DecimalFormat("###.###").p arse("122. 222");
this is what i have so far
String rate = "";
if (rate != "" && rate.length() > 0)
{
how do i use the above code here (Number x = new DecimalFormat("###.###").p arse("122. 222");)
}
thanks
>>>Number x = new DecimalFormat("###.###").p
this is what i have so far
String rate = "";
if (rate != "" && rate.length() > 0)
{
how do i use the above code here (Number x = new DecimalFormat("###.###").p
}
thanks
String rate = "122.222";
try {
Number x = new DecimalFormat("###.###").parse(rate);
} catch (ParseException ex) {
ex.printStackTrace();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(My comment takes your comment literally)
ASKER
thanks all
You might as well use Double.parseDouble, since those NumberFormat let most things through. Try
3.splat
for instance ;-)
3.splat
for instance ;-)
hello CEHJ
could you please explain this part of the regex?
(?: .... )?
thank you.
manuel
could you please explain this part of the regex?
(?: .... )?
thank you.
manuel
a. Don't save it
b. Allow one or zero occurences of it
(I assume you know what 'it' is - if not, let me know)
b. Allow one or zero occurences of it
(I assume you know what 'it' is - if not, let me know)
Yes, I know what 'it' is. Thank you for your response and your explanation!
Number x = new DecimalFormat("###.###").p