What is the type of variable by which we can input numerical value with float(33.67)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 11:57 AM
Hi expert,
I have created a "single line text" variable and under "type specification" tab, I have select validation regex as "number". But problem is it is not taking any flot value like 33.45, 6789.877 etc. and It is showing field error message " Not a number".
I have attached both screenshot, What is the type of variable by which we can input numerical value with float(33.67)?
Thanks
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 12:18 PM
The number validation is just checking if you have a number 0-9, not for decimals. You can create your own regex's to do things like this by navigating to;
- Service Catalog
- Catalog Variables
- Variable Validation Regex
- Catalog Variables
Once there you can create one, I called mine "Floating point" with this regex;
[+-]?([0-9]*[.])?[0-9]+
This will let you have things like;
.123
4.56
5
Then once you've made that, you can pick on your variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 09:29 AM
Hi @Jace Benson
also, catalog client script not adding(sum) floating values.
Code is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var value1 = g_form.getValue("p_amount");
var value2 = g_form.getValue("l_amount");
alert("value1: " + value1);
alert("value2: " + value2);
var sum = parseInt(value1) + parseInt(value2);
alert("sum: " + sum);
g_form.setValue('total_amount', sum);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 10:24 AM
The summary will not work because you have used parseInt() which returns an integer not a floating value.
You should switch to parseFloat() if you need to include decimal values.
Example below:
var a = '1.5';
var b = '2.3';
var sumInt = parseInt(a) + parseInt(b);
var sumFloat = parseFloat(a) + parseFloat(b);
gs.info('sumint: ' + sumInt);
gs.info('sumfloat: ' + sumFloat);
// output: -->> sumint: 3
// output: -->> sumfloat: 3.8

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 12:40 PM
Hi,
The OOB number validation is just that, it validates that you only have entered numerical values. Only [0-9] are allowed.
You can easily create your own custom validation by navigating to:
Service catalog > Catalog variables > Variable Validation regex
A regex that allows for both digits and a dot in between can look something like this:
[\d]+([.][\d]+)?