floor β GTM Variable Template for Number
floor EXTENDED Number
Rounds the provided input down to the nearest integer.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβRound down decimal
INPUT
Number To Round Down: 4.7
OUTPUT
4
Integer unchanged
INPUT
Number To Round Down: 10
OUTPUT
10
Live Sandbox
Section titled βLive SandboxβThis is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
floor
Number To Round Down
πΎ The number to round down to the nearest integer.
Supported formats:
β Number
β Stringified Number
Supported formats:
β Number
β Stringified Number
Input Setup
Input Function (optional)
βοΈ Optional pre-processing function applied to the input before internal logic (e.g., convert string to number, apply transformations). Internal transformations such as number conversion will still apply afterward.
Result Handling
Output Function (optional)
βοΈ Optional function to apply to the result before returning it (e.g., num => num + ' units', val => val.toString() for string conversion). Useful for chaining transformations on the output.
Number To Round Down number
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
floor()
Related Variables
Section titled βRelated VariablesβSame category: Number
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/*** Rounds the provided input down to the nearest integer.** @param {number} data.src - The number to round down.* @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format.** Direct-mode specific parameters:* @param {Function} [data.pre] - Optional pre-processor function to transform src before rounding.** @returns {number} The largest integer less than or equal to the input.** @framework ggLowCodeGTMKit*/const Math = require('Math');
const floor = function(value) { return Math.floor(value);};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// floor - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(floor(value));// ===============================================================================// floor() β Apply Mode// ===============================================================================/*return function(value) { return out(floor(value));};*/π§ͺ View Test Scenarios (5 tests)
β
'[example] Round down decimal'β
Negative decimal number - should round downβ
'[example] Integer unchanged'β
Zero - should return zeroβ
Small positive decimal - should round down to zero