Need more than 6 numbers after the decimal point

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 9:12 am

Hello LC devs,
I hope someone has a clever suggestion?
I can not get LiveCode to calculate an outcome with more than 6 figures after the decimal point.

Code: Select all

Set the numberformat to "0.############"
put 2/3.2514789 into tAnswer
the LiveCode outcome is 0.615105
However, the more digit outcome is 0,615104714350138

Any suggestions?

Regards,

Paul

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

Re: Need more than 6 numbers after the decimal point

Post by richmond62 » Wed Apr 15, 2020 9:20 am

Well, if it is any comfort I did this:

Code: Select all

on mouseUp
   put (2000000000 / 3.2514789)
end mouseUp
and got

615104714.350138

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 10:25 am

Thanks for the suggestion Richmond :) . For now I will go into this direction with building a small numbers DIV function.

It does not explain why the

Code: Select all

set the numberFormat
does not show more numbers after the decimal.
The dictionary states that it calculates to eighteen decimal places. it would be nice to be able to show as much.
Note: Since LiveCode does not use decimal numbers for its internal calculations (for reasons of speed), the decimal representation of a number is sometimes slightly off the correct number. For example, 10^-1 is equal to 0.1, but is calculated (to eighteen decimal places) as 0.100000000000000006.

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

Re: Need more than 6 numbers after the decimal point

Post by richmond62 » Wed Apr 15, 2020 11:02 am

mrcoollion wrote:
Wed Apr 15, 2020 10:25 am
The dictionary states that it calculates to eighteen decimal places. it would be nice to be able to show as much.
The dictionary states many things . . . 8)

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

Re: Need more than 6 numbers after the decimal point

Post by richmond62 » Wed Apr 15, 2020 11:07 am

This worked in LC 7.1.4:

Code: Select all

on mouseUp
   set the numberformat to ".##################"
   put 2/3.2514789
end mouseUp
0.615104714350137693

AND it worked in LC 8.1.8

Sorry, messing around on a machine running MacOS 10.7.5, so no higher version to test over here.

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 11:09 am

After some stupid goofing around with options how about this for a funky solution :shock: :D :shock: :D :D :D :D

Code: Select all

set the numberformat to "0.##################"
put 2/325147890 into tComputeAnswer
try
set the showValue of tComputeAnswer to true
catch errorParameter
put item 4 of line 1 of errorParameter into  tComputeAnswer
end try
Also works fine with
put 0.00000532*2 into tComputeAnswer
put 2/3.2514789 into tComputeAnswer

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 11:57 am

Build into a ManyDigitsFormula function (might have some typos because I cannot copy paste from script in the LC IDE)
However, due to engine restriction, the max number of digits after the decimal is 18! Higher becomes 0.

Code: Select all

put ManyDigitsFormula_v1 (2/325147890) into tAnswer

function ManyDigitsFormula_v1 tInFormula
   put "Put " & tInFormula & " into tComputeAnswer" into tComputeFormula
Do tComputeFormula
try
   set the showValue of tComputeAnswer to true
   catch errorParameter
   put item 4 of line 1 of errorParameter into  tComputeAnswer
end try
return tComputeAnswer
end ManyDigitsFormula_v1
Last edited by mrcoollion on Wed Apr 15, 2020 12:06 pm, edited 1 time in total.

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

Re: Need more than 6 numbers after the decimal point

Post by richmond62 » Wed Apr 15, 2020 12:00 pm

mrcoollion wrote:
Wed Apr 15, 2020 11:57 am
I cannot copy paste from script in the LC IDE
I have come across this problem once or twice.

The solution is to copy-paste from the IDE into a Text Editor, and then copy-paste from the text editor
into this thing.

OK, OK, I know that seems slightly mental: but it works. 8)

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 12:07 pm

Hi Richmond.. tried copy and paste into notepad++ but no luck. There is also no paste option is if do this via the application menu.
Last edited by mrcoollion on Wed Apr 15, 2020 12:27 pm, edited 1 time in total.

bogs
Posts: 4675
Joined: Sat Feb 25, 2017 10:45 pm

Re: Need more than 6 numbers after the decimal point

Post by bogs » Wed Apr 15, 2020 12:16 pm

*Answer moved to the correct thread....
Last edited by bogs on Wed Apr 15, 2020 3:18 pm, edited 1 time in total.
Image

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 12:32 pm

Hi B,
by bogs » Wed Apr 15, 2020 12:16 pm

Which vers. of Win and Lc Paul?
LC Indy 9.6 (dp3)
Windows 10 Pro ; Version 1903 ; build 18362720

bogs
Posts: 4675
Joined: Sat Feb 25, 2017 10:45 pm

Re: Need more than 6 numbers after the decimal point

Post by bogs » Wed Apr 15, 2020 1:01 pm

* Ditto...
Last edited by bogs on Wed Apr 15, 2020 3:18 pm, edited 1 time in total.
Image

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Need more than 6 numbers after the decimal point

Post by mrcoollion » Wed Apr 15, 2020 1:02 pm

Let me know. If you do not have issues with copy-paste on Windows 10 in p.6 (dp3) it must be something is changed...

bogs
Posts: 4675
Joined: Sat Feb 25, 2017 10:45 pm

Re: Need more than 6 numbers after the decimal point

Post by bogs » Wed Apr 15, 2020 1:35 pm

Mind you, I don't have Win 10 Pro, so the test is incomplete in covering every aspect of this.

However, on just regular Win 10, with Lc 9.6 DP 3, I was unable to recreate a situation where I could not copy from Lc and paste into Notepad using any regular method, i.e. ctrl + c, edit menu -> copy, etc.

Here is a link to a few of the shennanigans I used to test it - https://youtu.be/RZhEkwNsz0o
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6696
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Need more than 6 numbers after the decimal point

Post by dunbarx » Wed Apr 15, 2020 2:28 pm

Paul.

The engine does a lot of stuff behind the scenes so we do not have to type variables. Sometimes just setting the numberFormat don't cut it. Try this:

Code: Select all

on mouseup
   set the numberformat to "0.##################"
put 2/3.2514789 into tAnswer
   put "" & tAnswer into tAnswer
end mouseup
It was Jacque, with whom I had a similar discussion years ago, that made me appreciate this. You have to force the engine into transforming the number into a string before you get the format you want. Usually, adding "0" or multiplying by "1" does the trick. I just experimented with concatenating empty, and that works fine as well.

It is a small price to pay for typeless variables.

Craig

Post Reply

Return to “Talking LiveCode”