Hi Friends,
This is my first Blog and i want to share u some examples of System.Math() in Salesforce.
it will help in using math functions in ur running projects and by the way i am new to sales force.
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
Example for Math.Round():-
Decimal d = 12.12423432523;
Decimal i=Math.Round(d);
system.debug('Result::::::::::'+i);
------------------------------------------------------------------------------------------
Example for rounding decimal Direct method:-
Decimal i=Math.Round(d);
system.debug('Result::::::::::'+i);
------------------------------------------------------------------------------------------
Example for rounding decimal Direct method:-
Decimal d = 2.12345;
d=d.setscale(3);
system.debug('Result::::::::::'+d);
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
Example of Math.abs():-
Integer l = -42;
Integer m=math.abs(l);
system.debug('Result::::::::::'+m);
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Example of Math.ceil():-
Integer WeekOfMonth = Math.ceil((Double)(system.today().Day()) / 7).intValue();
system.debug('Result:::::::::'+ WeekOfMonth);
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Example for rounding decimal & double Direct method:-
Decimal d = 1.426 ;
Double num = d.setScale(2) ;
System.debug('Result::::::::::::: ' + num) ;
--------------------------------------------------------------------------------------------
Example for using power in salesforce:-
Decimal myDecimal = 4.12;
Decimal powDec = myDecimal.pow(2);
system.debug('Result::::::::::'+powDec);
---------------------------------------------------------------------------------------------
Example for using Math.max() :-
Integer larger = math.max(12, 156);
Decimal large = math.max(22.5,100.8);
system.debug('Result::::'+Larger);
system.debug('Results::::'+large);
----------------------------------------------------------------------------------------------
Example for using Math.min() :-
Integer small = math.min(12, 156);
Decimal smaller= math.min(22.5,100.8);
system.debug('Result::::'+small);
system.debug('Results::::'+smaller);
----------------------------------------------------------------------------------------------
Example for using Math.mod() :-
Integer Reminderval = math.mod(12, 2);
system.debug('Result::::'+Reminderval );
-----------------------------------------------------------------------------------------------
Example for using Precision() :-
Returns the total number of digits for the Decimal. For example, if the Decimal value was 123.45, precision returns 5.
Decimal d1=1234.567;
Integer precision1 = d1.precision();
system.debug('Result::::'+precision1 );
System.debug('Result::::::::::::: ' + num) ;
--------------------------------------------------------------------------------------------
Example for using power in salesforce:-
Decimal myDecimal = 4.12;
Decimal powDec = myDecimal.pow(2);
system.debug('Result::::::::::'+powDec);
---------------------------------------------------------------------------------------------
Example for using Math.max() :-
Integer larger = math.max(12, 156);
Decimal large = math.max(22.5,100.8);
system.debug('Result::::'+Larger);
system.debug('Results::::'+large);
----------------------------------------------------------------------------------------------
Example for using Math.min() :-
Integer small = math.min(12, 156);
Decimal smaller= math.min(22.5,100.8);
system.debug('Result::::'+small);
system.debug('Results::::'+smaller);
----------------------------------------------------------------------------------------------
Example for using Math.mod() :-
Integer Reminderval = math.mod(12, 2);
system.debug('Result::::'+Reminderval );
-----------------------------------------------------------------------------------------------
Example for using Precision() :-
Returns the total number of digits for the Decimal. For example, if the Decimal value was 123.45, precision returns 5.
Decimal d1=1234.567;
Integer precision1 = d1.precision();
system.debug('Result::::'+precision1 );
----------------------------------------------------------------------------------------------
For more methods in maths please use the below link:-
@http://docs.database.com/dbcom/en-us/db_apex/apex_methods_system_decimal.htm@
@http://docs.database.com/dbcom/en-us/db_apex/apex_methods_system_math.htm@
For more methods in maths please use the below link:-
@http://docs.database.com/dbcom/en-us/db_apex/apex_methods_system_decimal.htm@
@http://docs.database.com/dbcom/en-us/db_apex/apex_methods_system_math.htm@
If u have any other examples please share with me
Thanks&Regards
Hecthick
hi gud example of math methods
ReplyDeletegood example
ReplyDelete