Confused with currency and decimals

Hey guys,

I am stuck, trying to pass some data to a webservice that requires the data to have two decimal places.

I have made some reading and turned my variables to currency (they are obviously representing currency values) and I saved all that in my database as currency with FOUR decimal places. That seems to be fine.

Now, what’s the right approach to pass that data to the webservice with only two decimal places ?

I am probably doing something wrong, it’s my first time with money… :slight_smile:

The data you pass to a webservice is in the form of a STRING. It doesn’t matter how it is stored in your application, you have to convert/format it in order to pass it to a webservice. So format it with 2 decimal places and you’re good to go.

The only wrinkle is whether the service is expecting an explicit decimal point, “1234.56”, or an implied decimal point, “123456”.

But “format” inserts a comma in the string, which is unsupported by the WS, if I am not mistaken…

This is the format the WS is expecting the data -> “1234.56”

Only if you ask it to. Look at the various format options. I think “#.00” would work for you.

I think the problem is related to the locale setting… here we use comma for decimals…

But if it’s not wrong I could do something like this


That probablly returns a number with a point as a decimal separator and two decimals…

Doesn’t work… If I just cutoff the last two decimals I get rounding errors… How do I do this ?

FORMAT will use comma and decimal point (period) differently depending on your locale

why not just round the number correctly?


[quote=263775:@Roman Varas]I think the problem is related to the locale setting… here we use comma for decimals…
Use Str with a format string that ALWAYS uses , and . regardless of locale

Sorry Norman, not sure I understand what you mean…

“why not just round the number correctly?”

I am ashamed to say it.

Thanks Dave, that worked

Now the question is… Should I store the data in the database rounded with two decimals, or with four ?

[quote=263773:@Roman Varas]
But “format” inserts a comma in the string[/quote]
Instead of using the format method use STR
It also allows you to use a format string BUT it never uses anything but “american settings” - , for thousands and . for decimal
If you make the format string “#######.00” then you get no thousands separators & a period for the decimal separator

Thanks a lot… I got it working now… Just still not sure whether to save data with 2 or 4 decimals…

Doesn’t really matter.

well I’m be darn… I NEVER knew that…