Results 1 to 7 of 7
Thread: Change a double value
- 10-26-2012, 05:48 PM #1
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 96
- Rep Power
- 0
Change a double value
Hi,
I am building a small accounting program that I will import transactions from a downloaded bank file.
Most of my code is getting pretty good, but I have one problem:
When I import the data from the file, the amounts in the file are either positive or negative (in or out)
Now inside my program I want to make 2 transactions: One negative and one positive.
So the question is: How can i change the amount from being positive to negative or negative to positive based on the amount from the file?
- 10-26-2012, 06:05 PM #2
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
Re: Change a double value
Show us what you've got and where you're getting errors/unexpected results.
- 10-26-2012, 06:32 PM #3
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 96
- Rep Power
- 0
Re: Change a double value
I am not getting any results yet, because I am not sure how to do it...
If this value is negative, like this example, I would like to make a new value like this:Java Code:Double value1 = -150.00;
And vice versa....Java Code:Double value2 = 150.00;
- 10-26-2012, 06:47 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 32
- Rep Power
- 0
Re: Change a double value
will switch it from negative to positive and vice versa.Java Code:Your value * -1
- 10-26-2012, 07:52 PM #5
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 96
- Rep Power
- 0
Re: Change a double value
But I get an error:Java Code:String Amount = textAmount.getText(); Amount = Amount.replace(" ", ""); Amount = Amount.replace(",", "."); double amount; if (!"".equals(Amount)) { amount = Double.parseDouble(Amount); }else{ amount = 0; } double amount2 = * -amount;
Java Code:illegal start of expression
- 10-26-2012, 08:07 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 32
- Rep Power
- 0
Re: Change a double value
The *(asterisk) has to be in front of the =(equals)
Java Code:// +150.00 double amount1 = 150.0; //-150.00 double amount2 = amount1 * -1;
- 10-26-2012, 08:14 PM #7
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 96
- Rep Power
- 0
Re: Change a double value
Work perfect. Thanks JBelg!!Java Code:String Amount = textAmount.getText(); Amount = Amount.replace(" ", ""); Amount = Amount.replace(",", "."); double amount; if (!"".equals(Amount)) { amount = Double.parseDouble(Amount); }else{ amount = 0; } double amount2 = amount * -1;
Similar Threads
-
Is this right to change the labels [row][2] into double?
By opeboy in forum AWT / SwingReplies: 2Last Post: 09-25-2012, 04:53 PM -
Change the integer variable to type double - is this right?
By Keke101 in forum New To JavaReplies: 1Last Post: 01-02-2012, 11:16 PM -
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
change the delay between double click in mouse listener
By itaipee in forum AWT / SwingReplies: 6Last Post: 03-17-2009, 02:23 AM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks