Math.floor always rounds down, Math.ceil always rounds up. Using Math.round uses half-even rounding mode, so you can simply say:

Integer result = Math.round(96.7);

Half-even means that if a value is exactly 0.5, it rounds to the nearest even number (96.5 rounds to 96, 97.5 rounds to 98). This is the most "fair" statistically speaking, but you need to follow other rules, you can:

Decimal value = 96.7;
Integer result = value.round(RoundingMode.HALF_UP);

Which would round up on 0.5 or higher, for example. You can read about all the rounding types here.

Answer from sfdcfox on Stack Exchange
🌐
Iqra Technology
iqratechnology.com › academy › salesforce-apex-training › math-class-in-apex
Math Class in Apex – Iqra Technology
July 29, 2025 - Round the number 9.3 to the nearest integer using Math.round(). 2. Round the number 12.89 down using Math.floor(). 3. Find the absolute value of -100.50 using Math.abs(). 4. Calculate the square root of 225 using Math.sqrt(). 5. Find the maximum between 77 and 99 using Math.max().
🌐
Forcetalks
forcetalks.com › home › salesforce® discussions › how to round the double to two decimal places in salesforce apex?
How to round the Double to two decimal places In Salesforce Apex? - Forcetalks
January 23, 2019 - Tagged: Code Snippet, Decimal, Double, Salesforce Apex, Salesforce Apex Code, Salesforce Help and Training ... What's nice about this one is you can use the setScale overload that lets you specify the rounding mode you want to use.
🌐
Blogger
forceguru.blogspot.com › 2011 › 06 › mathround-utility-in-salesforce.html
ForceGuru: Math.Round Utility in Salesforce
public Decimal roundNumber(Decimal ... ; } else { return 0 ; } } Presently salesforce provides Math.Round(your_number) which will return the number after rounding with no decimal values....
🌐
Salesforce Thinkers
salesforcethinkers.home.blog › 2020 › 04 › 14 › math-formula-operators-and-functions-in-salesforce
Math Formula Operators and Functions in Salesforce – Salesforce Thinkers
April 14, 2020 - Example : ABS(Total Amount) calculates the positive value of the Total Amount regardless of whether it is positive or negative. ... Rounds a number up to the nearest integer, away from zero if negative.
🌐
Blogger
forceschool.blogspot.com › 2011 › 06 › decimal-rounding-in-apex.html
Force School: Decimal Rounding in an Apex
Then I suggested him to basic mathematic formula that my teacher told me in 10th standard 1)Multiply your number with nth power of 10 where n is the decimal point up to which we want to round it. 2) Use Math.Round then 3)Again divide it with n th power of 10 He was amazed that is that the way ...
Find elsewhere
🌐
Salesforce Blog
sfdcpoint.com › home › apex random number salesforce
apex random number Salesforce - Salesforce Blog
November 20, 2018 - You are using `Integer.valueOf()` which will always round down, e.g. `Integer.ValueOf(9.9)` will return `9`. This makes it so that the only way you will retrieve the last element of the list is if `Math.random()` returns 1 which is a lower probability than any other element.
🌐
Stack Exchange
salesforce.stackexchange.com › tags › rounding › hot
Hottest 'rounding' Answers - Salesforce Stack Exchange
It's usually used to set the number of decimal places to be used, but you can pass it a negative number to round to the nearest 10, 100, 1000, etc... ... ... The length and decimal places are only enforced when editing data via the standard web UI.
🌐
Camp Apex
campapex.org › lesson › 63ee4217223ddd93200728c9
Learn Salesforce Apex Programming | Camp Apex
Learn Salesforce Development and how to code in Apex. Camp Apex pairs Apex coding lessons focused on beginners with a built-in code editor and challenges. You can learn Apex step by step and write code from the start.
🌐
Salesforcefaqs
salesforcefaqs.com › home › how to convert decimal to integer in salesforce apex
How to Convert Decimal to Integer in Salesforce Apex
May 9, 2025 - In Salesforce Apex, the Math.round() method rounds the decimal value to the nearest Integer(whole number).
🌐
YouTube
youtube.com › watch
Math Class Methods - Apex Programming Level 5 ⭐⭐⭐⭐⭐ - YouTube
This video explains different methods of Math class in Apex.Please subscribe if you haven't subscribed to us yet - https://bit.ly/3v61lv5--------------------...
Published   November 7, 2022
🌐
Salesforce Developers
developer.salesforce.com › forums
How to round a number to two decimal places?
On December 4, 2023, Salesforce Developers discussion forums joined the Trailblazer Community. Learn more with our FAQs!
🌐
Home Assistant
community.home-assistant.io › configuration
Apex Charts - rounding Numbers?! - Configuration - Home Assistant Community
August 7, 2022 - hey im playing a little with the Apex Charts but need some help. The Output is sometimes a high floating number… So I need to round them by 2 - but how?^^ type: custom:apexcharts-card chart_type: donut apex_config: plotOptions: pie: donut: background: transparent labels: show: true total: show: lafeslaftrue header: show: true title: Hausverbrauch show_states: true colorize_states: true series: - entity: sensor.openwb_dai...