Page 1 of 2

Price rounding: Delete after coma

Posted: Fri Jun 01, 2018 11:35 pm
by ace16vitamine
Hi,

with a simple

Code: Select all

select job,Price from t_order
I am reading the price informations from a product out of my MS SQL Database to generate emails and put this into data grid.

The Output from the select is:
AUM7759 7.78000000000000

What is to do that the output is AUM7759 7.78?


Stef

Re: Price rounding: Delete after coma

Posted: Fri Jun 01, 2018 11:42 pm
by richmond62
Check round

Check numberFormat

Code: Select all

set the numberFormat to "#.00"
select job,Price from t_order[

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 12:27 am
by ace16vitamine
Round does not work...

select job,ROUND(Price,2) from t_order

And I see that it is not a comma, it is a dot.
AUM7759 7.78000000000000

Stef

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 11:29 am
by ace16vitamine
And...

If I put the select into an array numberFormat does not work...

Code: Select all

put revDataFromQuery(tab,return,connID,sql_test) into t_array["vkpreise"]
Output:
22.333434343434
33.5444545545

(..)

Code: Select all

 set the numberformat of t_array["vkpreise"] to "#.00"
Error: Chunk error in object expression near "22.333434343434", char 1

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 12:11 pm
by Klaus
Hi Stef,

"the numberformat" is a GLOBAL property and not a property of any LC object!
But this will only apply to the result of a (even nonsense, see below) arithmetical operation like:

Code: Select all

...
put 1 into ttt
set numberformat to "x.xx"
## FORCE the neccessary math:
add 0 to ttt
put ttt
## -> 1.00
...
Better use the format() function, but you need to apply this to all of your neccessary values separately:

Code: Select all

...
put 1 into ttt
## This will FORCE 2 decimal places:
put format("%1.2f",ttt)
## -> 1.00
...
And yes, Livecode is ENGLISH, means it computes with the englisch decimal delimiter which is a DOT.


Best

Klaus

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 12:57 pm
by Klaus
Hi Stef,
ace16vitamine wrote:
Sat Jun 02, 2018 12:27 am
...
And I see that it is not a comma, it is a dot.
to solve this problem in e.g. german apps see: http://www.livecode-blog.de/forums/topi ... -addieren/

Best

Klaus

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 2:59 pm
by richmond62
englisch decimal delimiter
Really?

Surely: das englische Dezimaltrennzeichen ?

Here, in Bulgaria a comma is used, and a DOT is used as the sign for multiplication!

SO: "3.5" means 3,5 in the English speaking world, and

"3.5" means 15 in Bulgaria.
gert-frobe.jpg

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 3:00 pm
by Klaus
Yes, really!

Re: Price rounding: Delete after coma

Posted: Sat Jun 02, 2018 3:04 pm
by richmond62
Yes, really!
Now I understand why the Anglo-Saxons left northern Germany and moved to England:
they didn't like using the comma as a delimiter.

Previously they were known as the Angles, Saxons, and Jutes (they were comma-delimited): but when they moved to the British Isles they stopped all that nonsense and become the Anglo-Saxons!

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 5:42 pm
by ace16vitamine
Hi Klaus,,
Klaus wrote:
Sat Jun 02, 2018 12:11 pm

Better use the format() function, but you need to apply this to all of your neccessary values separately:

Code: Select all

...
put 1 into ttt
## This will FORCE 2 decimal places:
put format("%1.2f",ttt)
## -> 1.00
...
Example:

Content of t_array["vkpreise"]:
4.490000000000000000
5.490000000000000000
9.490000000000000000

Code: Select all

   put t_array["vkpreise"] into ttt
   put format("%1.2f",ttt)
Message: bad format string or parameter mismatch near "4.490000000000000000", char 1

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 5:47 pm
by Klaus
Hi Stef,

sure that the number in -> t_array["vkpreise"] uses the DOT as decimal delimiter? 8)


Best

Klaus

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 5:49 pm
by Klaus
Oops, sorry, missed your examples, but:
...
put 4.490000000000000000 into ttt
put format("%1.2f",ttt)
...
gives me 4.49 and no error!?

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 5:50 pm
by Klaus
AH, NOW I GET IT! You can only "format" ONE Number at a time and not a list of numbers!

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 6:00 pm
by ace16vitamine
Right ! The think is I got it with

4.4900000000



out of a database, put it in to an Array. And now I have no Idea how i can format it human readable :-)

Re: Price rounding: Delete after coma

Posted: Fri Jun 08, 2018 6:03 pm
by Klaus
ace16vitamine wrote:
Fri Jun 08, 2018 6:00 pm
And now I have no Idea how i can format it human readable
is this a question?