World: r3wp
[Core] Discuss core issues
older newer | first last |
Anton 14-Oct-2006 [5687x2] | No, I check the balance manually occasionally. |
It's really basic. What are you trying to do ? | |
Louis 14-Oct-2006 [5689x3] | Responding privately. |
I don't understand this: >> x: "9220" == "9220" >> r: "777777" == "777777" >> x: to-integer x == 9220 >> r: to-money r == $777777.00 >> d: r / x == $84.36 >> d * x == $777777.00 >> d * 9220 == $777777.00 >> $84.36 * 9220 == $777799.20 >> d == $84.36 >> What is happening there? | |
I had to post that before I go to sleep. I'll probably have to get up sometime through the night to see the answer. | |
Gregg 14-Oct-2006 [5692] | BUILD - 'ins and 'only are good words, it's just that plain words, mixed with a lot of other plain words, don't catch your eye, so using any other word doesn't solve it for me. That's why I used the set-word! syntax in my COLLECT function if you recall. I would probably end up using "special" words or marker values, e.g. puting special chars around the words, like ~ins~ or *only*, or just using special start/end markers. Basically, synthesizing a paren alternative or looking for words that are "marked up" in a ceratin way. e.g. build [1 [|_ 3 + 2 _| |_ now _|]] ; |_ val _| = ins val build [1 ||_ reduce [3 + 2 now] _|| ] ; ||_ val _|| - only val build [1 *this* and *that* but not these] ; marked words, e.g. *-modified, are reduced |
Ladislav 14-Oct-2006 [5693x5] | Louis - what you are describing is a MOLD issue - MOLD shows you only two decimal digits for the MONEY! datatype |
(which looks like less than you expect, doesn't it?) | |
on the other hand, the "full precision" is used for computing, that is why you see the difference | |
I am afraid, that you may be unable to use the current MONEY! datatype implementation for accounting purposes, because you probably don't know when you need to take care | |
(I don't think, you would be able to do better with DECIMAL! either due to the same issues) | |
Louis 14-Oct-2006 [5698x2] | Ladislav wrote: "you probably don't know when you need to take care." You are right, but I am going to have to learn. I have written a double-entry fund accounting program which we are using for our non-profit organization for several years. I have just modified it to convert rupiahs to dollars. But it also has to be able to convert the dollars back to rupiahs properly. Are there any documents I might read to educate myself? |
Here is samle data showing the problem: >> d: make object! [ [ reconciled-d: "o" [ reconciled-c: "o" [ trans-num: "1232" [ trans-date: 14-Oct-2006 [ check-num: "" [ vender: "" [ debit-fund: "GF" [ debit-acc: "5003" [ debit-amount: $84.36 [ debit-desc: "" [ credit-fund: "GF" [ credit-acc: "1001" [ credit-amount: $84.36 [ credit-desc: "" [ date-entered: 14-Oct-2006 [ user: "LAT" [ rp-per-dollar: "9220" [ ] >> d/debit-amount == $84.36 >> d/debit-amount * 9220 == $777799.20 >> The result should be $777777.00, so I am getting 22.2 rupiah too many. | |
Ladislav 15-Oct-2006 [5700x7] | the problem you are struggling with isn't REBOL-specific |
that is why you cannot find the solution in REBOL documentation | |
Mathematical rules: 1) do not expect, that a result "exists" unless you know it does | |
in the case you are describing we get: $84.35 * 9220 ; == $777707.00 $84.36 * 9220 ; == $777799.20 | |
we can conclude, that there is *no amount* expressible in dollars and cents that has got the properties you want it to have | |
The solution is up to you - you need to know what you really want and how to get it. | |
I guess that if you will be able to describe what you really want, there will be no problem to get it | |
Graham 15-Oct-2006 [5707] | If you're dealing with $777,777 - then I suggest a professional accounting package is more appropriate. |
Ladislav 15-Oct-2006 [5708] | I disagree, even when using a professional accounting package we need to know what we want to get |
Gabriele 15-Oct-2006 [5709] | graham, my guess is that they are rupiahs, not dollars :) |
Oldes 15-Oct-2006 [5710x4] | Louis: Ladislav is right, the money shows you just 2 decimals digits and rounds as you can see: >> 777777 / 9220 == 84.3575921908894 >> to-money 777777 / 9220 == $84.36 >> (to-money 777777 / 9220) * 1000 == $84357.59 >> (to-money 777777 / 9220) * 1000000 == $84357592.19 |
What is suprise for me is, that it's not possible convert money to decimal using: to-decimal $84.36 | |
I think, that money datatype is almost useless | |
For example why is not working this? >> $10 * $10 ** Script Error: Expected one of: number! - not: money! ** Near: $10.00 * $10.00 Money is not a number? | |
Anton 15-Oct-2006 [5714] | The specified unit ($) would also have to be multiplied to be consistent there. We had this discussion before when talking about the proposed Rebol v3 deci! datatype... Anyway, I agree there are problems, but this works: >> 10 * $10 == $100.00 |
Ladislav 15-Oct-2006 [5715] | Oldes - you *can* convert money! to decimal as follows: second $84.36 ; == 84.36 |
Anton 15-Oct-2006 [5716] | I wish I could divide the money in my bank account into $10 amounts and then just multiply them, but the bank won't let me. I don't know why. |
Oldes 15-Oct-2006 [5717x4] | Ok, you are right, I know I can do 10 * $10 and it's probably logical, but anyway, for me money is a number and this is new form me: >> second (to-money 777777 / 9220) == 84.3575921908894 |
(anyway, I'm not going to use money datatype) | |
and it should be possible to do $10 * $10 as in the Louis' example above, the number 9220 should be money datatype as well as it is number of roupies per dollar (if I understand it well) so he should use RP$9220 if he is using money! for dollars | |
I doubt, someone is using this feature (currency identifier) with money datatype:-) | |
Anton 15-Oct-2006 [5721x4] | Louis' example did not multiply two money!s. |
and I strongly disagree that you should be able to multiply two money!s. | |
A currency exchange rate (such as Louis' 9220) includes, as part of its definition, two distinct currencies (eg. RP and USD). | |
Anyway, I don't want to argue this, you should know about how to handle units. Everyone should know that 10 Metres x 10 Metres does not equal 100 Metres. | |
Louis 15-Oct-2006 [5725] | All this is very interesting. I appreciate all of your comments. Anyway I have a workaround to the problem. First of all, however, I need to tell you why I wanted to be able to convert dollars back to rupiahs. It was just to save space in the database. I enter rupiahs, as that is the currency I am using right now, but the software converts it to dollars and saves the dollar amount to the database. To find out the rupiah amount later if needed, I was going to do a reverse conversion. The other solution is to simply record the rupiah amount in the database also, so that is what I'll do. |
Oldes 15-Oct-2006 [5726] | by the way, you may use the conversions on the side of the database during select |
Louis 15-Oct-2006 [5727] | Oldes, please explain. I do not understand what you mean. |
Oldes 15-Oct-2006 [5728] | mysql> create table test (dolars float(2)); Query OK, 0 rows affected (0.22 sec) mysql> insert into test values(777777); Query OK, 1 row affected (0.03 sec) mysql> select dolars,(dolars / 9220) as rupias from test; +--------+-----------------+ | dolars | rupias | +--------+-----------------+ | 777777 | 84.357592190889 | +--------+-----------------+ 1 row in set (0.01 sec) |
Louis 15-Oct-2006 [5729x2] | So I could get the reverse conversion I want if I were using mysql? |
Right now I'm simply using a rebol object database. It would be very difficult to change this particular script. But if I ever do something like this again I may consider using mysql. | |
Oldes 15-Oct-2006 [5731x2] | If you are using Rebol, you should probably use decimals, not money datatype |
(to store it in the database) | |
Louis 16-Oct-2006 [5733x3] | Oldes, yes. I can see that you are right. Store in decimal. Display in money. >> r: 777777 == 777777 >> x: 9220 == 9220 >> d: r / x == 84.3575921908894 >> d * x == 777777.0 >> to-money d == $84.36 >> |
I've converted the script to decimal, and it works great! | |
Decimal is converted to money for reports. | |
BrianH 16-Oct-2006 [5736] | Watch out though - your problem wasn't a decimal vs. money problem, it was a rounding problem. If you are going to store the dollar equvalent in a database make sure to store it as a floating-point value rather than a fixed-point like SQL's decimal type. Otherwise you are going to run into the same problem when you store the data and retrieve it again. |
older newer | first last |