Skip to content

ceil β€” GTM Variable Template for Number

VARIABLES β€Ί NUMBER
ceil EXTENDED Number
Direct (.tpl) Apply (.tpl)

Rounds the provided input up to the nearest integer.



Round up decimal
INPUT
Number To Round Up: 4.3
OUTPUT
5
Integer unchanged
INPUT
Number To Round Up: 5
OUTPUT
5

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

ceil
Number To Round Up
πŸ’Ύ The number to round up to the nearest integer.

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 mathematical operations). Internal transformations such as type handling 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 Up number
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
ceil()


πŸ“œ View Implementation Code
/**
* Rounds the provided input up to the nearest integer.
*
* @param {number} data.src - The number to round up.
* @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 input before rounding.
*
* @returns {number} The smallest integer greater than or equal to the input.
*
* @framework ggLowCodeGTMKit
*/
const Math = require('Math');
const ceil = function(value) {
return Math.ceil(value);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// ceil - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(ceil(value));
// ===============================================================================
// ceil() – Apply Mode
// ===============================================================================
/*
return function(value) {
return out(Math.ceil(value));
};
*/
πŸ§ͺ View Test Scenarios (7 tests)
βœ… '[example] Round up decimal'
βœ… Round up negative decimal
βœ… '[example] Integer unchanged'
βœ… Round up zero - should return 0
βœ… Round up string number - should convert and round
βœ… Undefined input - should return NaN
βœ… mpty string - should return 0