Home : Products : Gossamer Links : Development, Plugins and Globals :

## Small global for mathematical function

Hello,

i need a small global that perform this mathematical function:

- I have a number A (e.g. 7488)
- I have a number B (e.g. 1000)
- I need two numbers C and D:
- the number C is from this operation: A / B = 7,488 without comma-numbers, result is "7"
- the number D is: A (7488) - ( C (7) * B (10) ), result is "488"

How can i get this seperate two numbers in a small global?

Coyu
Hi,

Try;

Code:
sub {

my \$aa = \$_[0];
my \$bb = \$_[1];

my \$cc = \$aa / \$bb;
my \$dd = \$aa - (\$cc * \$bb);

return { aa => \$aa, bb => \$bb, cc => \$cc, dd => \$dd }

}

Call with;

<%global_name(A,B)%> (where A or B are the number, or something like \$FieldName).

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Hey Andy,

thx! ,-)

I need both numbers seperately. Could i say something like:
<%global_name(A,B,output_C)%>
<%global_name(A,B,output_D)%>

???

Coyu

Hi,

You can just use;

<%aa%>, <%bb%>, <%cc%> and <%dd%> .. to their respective values =)

i.e;

<%global_name(A,B)%>
A = <%aa%>
B = <%bb%>
C = <%cc%>
D = <%dd%>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Hey Andy,

i use your global this way:
<%globalname(7488,1000)%>
And get as result for
cc = 7.488 (but it should be "7") and for
dd = 0 (should be 4.88)

What should i do wrong?

Greetings,

Coyu
I think you can use the sprintf to format the number before the return. Somthing like below should work

\$cc = sprintf("%.0f",\$cc);
\$dd = sprintf("%.2f",\$dd);

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Hey Dat,

\$cc = sprintf("%.0f",\$cc);

was very helpful. Thank you!!!
But i need always round off "cc". How can i make this?

Greetings,

Corc

I think we can use the int function for that. For example, \$cc = int (\$aa/\$bb);

Is that what you want?

Cheers,

Dat

Programming and creating plugins and templates
Blog