how to get 2.5 from 5/2

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
suda
Posts: 19
Joined: 02 Feb 2016 02:52

how to get 2.5 from 5/2

Post by suda » 11 May 2017 05:52

num=5/2;
ans="{num,numberformat,0.0}";

//I want 2.5 as answer ,but returned value is 2.0
//Teach me how to get 2.5 ,please.

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: how to get 2.5 from 5/2

Post by Bingwu » 11 May 2017 06:11

Hello Suda!

Make a point behind the divisor:
num=5/2.;
regards
Peter

suda
Posts: 19
Joined: 02 Feb 2016 02:52

Re: how to get 2.5 from 5/2

Post by suda » 11 May 2017 07:22

Soon answer, Thank you!
I could get 2.5.
5/2. is Hidden function?

Recently i found "old_global_....."!
I think this function is good.

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: how to get 2.5 from 5/2

Post by Bingwu » 11 May 2017 07:54

Hello Suda!

I am myself desperate at this "problem"! An official documentation or help is not known to me.
After a long search I found this post: http://automagic4android.com/forum/view ... oint#p8246

regards
Peter

suda
Posts: 19
Joined: 02 Feb 2016 02:52

Re: how to get 2.5 from 5/2

Post by suda » 12 May 2017 14:24

Certainly, Strange...
"5/2 is 2.5" is simply than "5/2 is 2".
I think so.

For a long search, thank you.

Augugusto
Posts: 5
Joined: 31 Mar 2017 15:26

Re: how to get 2.5 from 5/2

Post by Augugusto » 15 Jun 2017 15:18

The problem is that if you divide using integers it asumes that the output will be an integer so it deletes the decimals. If you add a '.' or '.0' after at least one of the numbers, it predicts the result as a float and you get the decimals

Edit: if you were using variables (or if you want to) I think you can just put "(float)" in front of one of the parts of the division

suda
Posts: 19
Joined: 02 Feb 2016 02:52

Re: how to get 2.5 from 5/2

Post by suda » 12 Sep 2017 02:39

Thank you!

In short, for example, when dividing, if you want decimal values, add ". 0" somewhere in the calculation formula. Is that it? It is okay.

I am using google translator. It became easy.

Post Reply