GdLimitNumberPipe
The GdLimitNumberPipe is an Angular pipe that limits the display of a number to a specified maximum value, appending a suffix when the number exceeds this limit.
Import
import { GdLimitNumberPipe } from '@geodome/gdk/common';
Usage
{{ someNumber | limitNumber:100 }}
or with a custom suffix:
{{ someNumber | limitNumber:100:'++' }}
Parameters
value: The number to be limited.maxValue: The maximum value to display before applying the suffix.suffix(optional): The string to append when the value exceedsmaxValue. Defaults to '+'.
Behavior
- If the input
valueis greater thanmaxValue, it returnsmaxValuefollowed by the suffix. - If
valueis less than or equal tomaxValue, it returnsvalueas is. - If either
valueormaxValueis not a valid number, it returns the originalvalue.
Examples
{{ 75 | limitNumber:100 }} // Output: 75
{{ 150 | limitNumber:100 }} // Output: 100+
{{ 200 | limitNumber:100:'++' }} // Output: 100++
Use Cases
- Displaying follower counts on social media (e.g., "999+")
- Showing item counts in lists or inventories
- Limiting displayed numerical values in UI elements
note
This pipe is particularly useful for creating clean and consistent number displays in user interfaces, especially when dealing with potentially large numbers.