Price rounding: Delete after coma

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Price rounding: Delete after coma

Post by ace16vitamine » Fri Jun 01, 2018 11:35 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Price rounding: Delete after coma

Post by richmond62 » Fri Jun 01, 2018 11:42 pm

Check round

Check numberFormat

Code: Select all

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

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Price rounding: Delete after coma

Post by ace16vitamine » Sat Jun 02, 2018 12:27 am

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

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Price rounding: Delete after coma

Post by ace16vitamine » Sat Jun 02, 2018 11:29 am

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Sat Jun 02, 2018 12:11 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Sat Jun 02, 2018 12:57 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Price rounding: Delete after coma

Post by richmond62 » Sat Jun 02, 2018 2:59 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Sat Jun 02, 2018 3:00 pm

Yes, really!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Price rounding: Delete after coma

Post by richmond62 » Sat Jun 02, 2018 3:04 pm

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!

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Price rounding: Delete after coma

Post by ace16vitamine » Fri Jun 08, 2018 5:42 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Fri Jun 08, 2018 5:47 pm

Hi Stef,

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


Best

Klaus

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Fri Jun 08, 2018 5:49 pm

Oops, sorry, missed your examples, but:
...
put 4.490000000000000000 into ttt
put format("%1.2f",ttt)
...
gives me 4.49 and no error!?

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Fri Jun 08, 2018 5:50 pm

AH, NOW I GET IT! You can only "format" ONE Number at a time and not a list of numbers!

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Price rounding: Delete after coma

Post by ace16vitamine » Fri Jun 08, 2018 6:00 pm

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 :-)

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Price rounding: Delete after coma

Post by Klaus » Fri Jun 08, 2018 6:03 pm

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?

Post Reply

Return to “Databases”