In most languages that use it, it represents the modulus operation.
In APEX, you use Math.Mod()
if (Math.Mod(x, 2) == 0) {
system.debug(x + ' is even');
}
APEX Expression Operators Reference shows that there is no definition of a % operator.
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.apexref.meta › apexref › apex_methods_system_math.htm
Math Class | Apex Reference Guide | Salesforce Developers
Contains methods for mathematical operations.
Videos
09:53
Apex Use Case 7 & 8 | Chapter 67 | Salesforce Developer Masterclass ...
Arithmetic Operators in Apex - Salesforce Apex Tutorial Part 18
06:32
Add And Subtract Operators In Apex | Salesforce Development Tutorial ...
15:19
Apex Test 04 | Even and Odd Number - YouTube
Infallibletechie
infallibletechie.com › 2012 › 11 › mathematical-functions-using-apex-in.html
Mathematical functions using apex in Salesforce – InfallibleTechie
Integer result; //Finding minimum value result = math.min(a,b); //Finding maximum value result = math.max(a,b); //Modulo division result = math.mod(a,b); · http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_math.htm
Salesforce
ideas.salesforce.com › s › idea › a0B8W00000GdfgZUAR › provide-mathmod-as-an-operator
Provide Math.mod() as an operator. - IdeaExchange - Salesforce
Loading · ×Sorry to interrupt · Refresh
Pablo Gonzalez
pablogonzalez.io › apex-methods-should-do-one-thing-but-what-is-one-thing
Efficient Apex: methods should do one thing, but what is one thing?
July 10, 2024 - public class Password { public ... = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length()); password += chars.substring(idx, idx+1); } return password; } } ... The Site class has some methods for reseting password. This use case is simply an illustration and not an encouragement to re-create existing logic from the Apex ...
Top answer 1 of 2
2
As of Spring 19 (and all prior versions), we only have mod(Integer, Integer) and mod(Long, Long). There is no known information of when, or if, we might get a built in for Decimal or Double values.
2 of 2
3
In case anyone happens upon this page, one way to do this is (assuming someDecimal is non-null):
Decimal remainder = someDecimal - someDecimal.round(RoundingMode.DOWN);
Salesforce Developers
developer.salesforce.com › forums
modulus operator in apex classes
On December 4, 2023, Salesforce Developers discussion forums joined the Trailblazer Community. Learn more with our FAQs!
Blogger
salesforcetechsolution.blogspot.com
Salesforce and Apex
This also allows you to // get strings in the form of "forty-five hundred" if called directly. public static String convert_nnn(integer val) { String word = ''; integer rem = val / 100; integer mod = Math.mod(val,100); if (rem > 0) { word = to_19[rem] + ' hundred'; if (mod > 0) { word += ' '; } } if (mod > 0) { word += convert_nn(mod); } return word; } public static String english_number(long val) { if (val < 100) { return convert_nn(val.intValue()); } if (val < 1000) { return convert_nnn(val.intValue()); } for (integer v = 0; v < denom.size(); v++) { integer didx = v - 1; integer dval = (inte
Salesforce Developers
developer.salesforce.com › docs › marketing › marketing-cloud-ampscript › references › mc-ampscript-math › mc-ampscript-reference-math-mod.html
Mod() | Math Functions | AMPscript for Marketing Cloud Engagement | Salesforce Developers
The function returns the modulus of the two numbers: 8 (500 divided by 12 is 41 with a remainder of 8).
Salesforcefaqs
salesforcefaqs.com › mod-function-in-salesforce
MOD() Function in Salesforce | Syntax, Examples, & Use Cases
October 10, 2025 - The MOD() function in Salesforce is a mathematical function used to perform calculations.
Apex Hours
apexhours.com › home › salesforce developer › what is apex? a complete guide
What is Apex? A Complete Guide - Apex Hours
Introduction to Apex Part 1 : Assignment completed ... Integer sum=0; for (Integer i =1; i<=20; i++) { mylist.add(i); //system.debug(mylist); } Integer j = 0; while(j < 20 ) { integer check=math.mod(j, 2); if(check == 0) { sum = sum + mylist[j]; } j++; } System.debug('Sum is ' +sum);
Published June 10, 2024
Salesforce Blog
sfdcpoint.com › home › apex random number salesforce
apex random number Salesforce - Salesforce Blog
November 20, 2018 - Integer randomNumber = Integer.valueof((math.random() * 10)); Boolean randomBoolean = Math.mod(randomNumber,2) == 0 ? true : false; System.debug('randomBoolean is'+randomBoolean); List<String> availableValues = new List<String>{'Red','Green','Blue','White','Black'}; Integer listSize = availableValues.size() - 1; Integer randomNumber = Integer.valueof((Math.random() * listSize)); String randomString= availableValues[randomNumber]; System.debug('randomString is'+randomString); Apex, salesforce ·
Apexsandbox
apexsandbox.io › problem › 5
Apex Practice Problems - ApexSandbox.io
Become an expert Apex developer with a growing collection of Apex programming problems
Reddit
reddit.com › r/salesforce › mod() function help
r/salesforce on Reddit: MOD() function help
July 10, 2016 - For example, I understand the smaller examples the help text uses MOD(123, 100) = 23 because 123/100 = 1.23 with 23 being the remainder. But what about larger numbers like the example suggests using dates? I tried to understand the example they used by replacing the generic "My_Date__c" with a specific date.
salesforce-solutions
subhashrdssv.wixsite.com › salesforce-solutions › single-post › 2016-1-23-converting-a-number-to-text-using-apex-trigger-and-apex-class
Converting a Number to Text using Apex Trigger and Apex Class
January 23, 2016 - '' + convert(math.mod(i , 10)):''); if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred and' + ((math.mod(i , 100) > 0)?' ' + convert(math.mod(i , 100)):''); if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + convert(math.mod(i , 1000)):''); if( i < 100000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)?