I have an issue which I need some help on. I have a web app which the user input an amount into a text field (in this format: 00.00) which is passed to the form as a string. I use double.parse double so I can assign it to a currency value. I have posted some code which doesn't give me any warning:
aQuantity is a double as well. Here is my issue currency.aQuantity is passed to another class which is looking for currency and not a double. Is there a way to convert/cast the double to currency or another way around the problem? Everything I have read said using doubles for currency is a bad idea. Since I have the number formatted the way I want it, my thinking was it shouldn't be a problem. If I'm heading the wrong direction with the double cast, please point me in the right direction. Thanks in advance.
Frankly I do not understand your predicament. Using double for currency is not a good idea, when you could expect singular entries to be in around the Uncle Scrooge amounts. However, cannot bring myself to understand why to expect troubles in a two decimal setting.
You talk of passing the double to another class, that looks for currency, and casting the double to currency etc. What in this context is the "currency", apparently not the Java Currency -class? But since, only input that you reveal to us, is just the primitive double, how in the world do you go about "looking for currency" in a primitive value? Simple double dont have that fancy hairdos.
And basically, you cannot cast a primitive type to any actual class, save for a suitable wrapper class (such as Number, Double etc.). Without knowing more of the currency you are referring to, whats it like, how is it used etc. I cannot say if you can cast a double to that. However, it is safe to assume, that would seldom be a good approach.
As such, provided the text passed to Double.parseDouble(...) is working, you do get a double. Else you get an exception. So, post again, include the problem.