Re: String To BigDecimal - [SOLVED]
Re: String To BigDecimal - [SOLVED]
- Subject: Re: String To BigDecimal - [SOLVED]
- From: "Jonathan Fleming" <email@hidden>
- Date: Thu, 18 Sep 2003 10:16:30 +0100
Thanks Pierre, that's another on solved and everyone else who contributed.
Jonathan :^)
From: Pierre Frisch <email@hidden>
To: "Jonathan Fleming" <email@hidden>
CC: email@hidden, email@hidden
Subject: Re: String To BigDecimal - Is it Possible?
Date: Wed, 17 Sep 2003 08:29:53 -0700
Hi Jonathan,
Could you check the scale of your attribute in the model? and tell us which
DB you are using.
I found that you have just highlighted my problem. I had learnt late in the
day that I needed to set scale in the database (MSSQLServer2000) to get my
decimal places to the right, but never even thought about it in the EOModel,
once I did that everything just worked. I'll remember in future to set this
when using decimals as I had never had to do this before... at least I don't
think I have.
Try to write the validation method as
public BigDecimal validatePrice(Object newPrice)
it is faster anyway.
public BigDecimal validatePrice(Object newPrice) didn't work, it gave me a
type error but
public Object validatePrice(Object newPrice) did work. Is this OK to go
ahead with?
The add a statement to test the class of the object that you get. Something
like
NSLog.out.appendln("==========\r newPrice class " +
newPrice.getClass().getName() );
done
This will probably give you a clue of what is happening.
Pierre
On Wednesday, September 17, 2003, at 04:58 AM, Jonathan Fleming wrote:
From: email@hidden
To: Jonathan Fleming <email@hidden>
CC: email@hidden
Subject: Re: String To BigDecimal - Is it Possible?
Date: Tue, 16 Sep 2003 13:56:53 +0100
Hi Jonathan
On Tuesday, September 16, 2003, at 11:44 am, Jonathan Fleming wrote:
I'm trying to find out if it's posible to convert a String to a
BigDecimal in WO... is it?
I suppose you want something different from "new BigDecimal(aString)"?
What do you mean? I can tell you this, the statement works in part as it
will save whole numbers like 10, 44, 66, but fails to save 39.99, 46.64,
57.60... was this what you knew was going to happen?
So, no that's not what I want... numers with 2 decimal places is what I'm
after. Unless I'm doing something very wrong. Here's the validation I'm
using and as i say it works fine except for what I've said:
public BigDecimal validatePrice(BigDecimal newPrice)
/* I've also used it like this public Number validatePrice(Number
newPrice) but no difference */
throws NSValidation.ValidationException {
if (newPrice !=null)
{
String sPrice = newPrice.toString();
for (int index=0; index<sPrice.length(); index++)
{
char c = sPrice.charAt(index);
if (!Character.isDigit(c))
{
throw new NSValidation.ValidationException("The
value \"" + newPrice + "\" is not a valid Price. Avoid punctuations and
letters except (\".\") a decimal point. Try something like \"10.23\",
\"125\" etc.");
}
}
newPrice = new BigDecimal(sPrice);
NSLog.out.appendln("==========\r The newPrice is " +
newPrice );
} else if (budget() == null && saleStatus().equals("For
Sale")) {
throw new NSValidation.ValidationException("You must
choose \"Price\" if your sale status is set to \"For Sale\" or \"Budget\"
if it is set to \"Wanted\", and you can not choose both.");
}
return newPrice;
}
Jonathan :^)
-- Denis.
If so How. Can anyone help?
Thanks
Jonathan :^)
_________________________________________________________________
Express yourself with cool emoticons - download MSN Messenger today!
http://www.msn.co.uk/messenger
_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.