H
ere’s a quick post on a simple topic that should save people some frustration. I’ve seen questions for a while now about setting up the number of decimal places for a field in ServiceNow. ServiceNow has a ‘Decimal’ field type that can be used for this, but that field type limits you to no more than two decimal places unless you understand the trick to adding more. In this post I’ll show you the trick to controlling the number of decimal places for a decimal field in ServiceNow.
The first step is to set up your decimal field. You can do this by personalizing the form or list for the table where you need the decimal field. The new field type should be ‘Decimal’ as shown in the screenshot below.
Now for the important part! When a decimal field is created it is set up with a ‘Max length’ value of 15. You can verify this by personalizing the dictionary for your new field. This also means that your decimal field is limited to NO MORE THAN 2 DECIMAL PLACES BY DEFAULT. If you want to extend that, you need to make a couple of adjustments to the dictionary entry for your field.
If you’re not there already, open the dictionary entry for the field by right-clicking the decimal field label and selecting ‘Personalize -> Dictionary’. Once there, you’ll need to adjust both the ‘Max length’ and ‘Attributes’ fields as shown below. The decimal places are a combination of ‘Max length’ and the ‘scale’ attribute. If you want 4 decimal places, you’ll need a ‘Max length’ of 4 plus the default of 15, or 19. Your ‘scale’ attribute would be set to 4, to indicate the number of decimal places. 6 decimal places would require a max length of 21 and a scale attribute of 6, and so on.
Thank you so much for posting this. This is one of many of your articles that have helped me.
I’m glad it helped! Please keep me in mind if you need consulting help in the future :).
Thank you for this article – I tried this today and noticed that the Scale attribute isn’t in the choice list under attribute menu tab. The workaround was that I had to go to the advance view link and actually type in the attribute into the attribute text field and use 26 in the max length. – Helsinki version/personal instance
Thanks for this Mark. We’ve been looking for this answer for a few months. It’s hard to believe that the builders of SNC didn’t think their users would need a decimal field that allows more than 2 decimal places. I really think this kind of detail should be included in the Wiki for all field types. I’m glad there are folks out there like you who can fill in the blanks for those of us who are building SNC for our users “on the outside”.
Thanks Jim. I’m glad it’s documented now so I won’t have to remember the secret in the future :).
Was trying to not truncate a trailing zero and this did not work for that. Any other solutions?
It appears that this no longer works for Berlin and up: http://wiki.servicenow.com/index.php?title=Talk:Introduction_to_Fields
According to the above link, Floating Point is fixed at 7 decimal places and decimal fields support 2. I was giving this a shot with a field that I have set to scale=4 and it was not working. Can anyone else confirm this?
does not work. it actually rounds off my decimals which is crazy!
Give it a test in a ServiceNow demo instance. It works there exactly as I’ve described here.
In Dublin the default decimal length is 20, so if you want 4 decimal places set scale=4 and Max Length = 24
The general rule is to set:
* Scale = (number of decimal places) and
* Max Length = (default length) + (number of decimal places)
Awesome, thanks for sharing! I haven’t had to deal with this issue for a while so I didn’t realize there was a change in Dublin.
Hey Mark! They have hidden the scale attribute in Eureka from the related list at the bottom, you have to click on Advanced to be able to do the in-line text version for the attributes field. Then you can add Scale there. Funny thing is, when you save the dictionary record, then the scale magically appears at the bottom.
Hey Everyone!
I still can’t get this to work on Eureka, at least not the way I expect it.
I’ve set the Decimal field to Maxlength 22 and added a scale=2 attribute to the dictionary field.
What appears to happen is that he maximum number of decimal places is now 2, but if the number ends in .X0 or .00 then the 0s are left out.
So 2.70 is displayed as 2.7 and 34.00 is displayed as 34.
If you have a Decimal field the next logical thing is to be able to display to a number of decimal places, but I still don’t see how to achieve this.
I have tried this but not able to resolve my issue. Can you please suggest.
Thanks
You’ll probably need to discuss with ServiceNow if none of the solutions here work. From what I understand, they’ve designed it specifically this way. Not much you can do about it as far as I’m aware.
We have decimal field and when we got the value with 2 decimals but for round of values like 25 or 30 , we need to make it as 25.00 and 30.00. This is not happening.
can any one suggest please.
Thanks,
Bhushan
Hi Mark,
I am facing an issue with decimal places. I have created 3 field in decimal. When I created them first of all it was taking more than 2 points after decimal. When I wanted to adjust it to 3 decimal places, I had given a Max Length of 18 and a scale of 3 in Attribute place, but I see it is taking upto 12 decimal places.
Previously also I had created decimal field, upto 5 decimal place. At that point of time I had given a Max Length of 20 and a scale of 5. It then worked perfectly.
Can you tell me the reason why is it not working, or am I doing something wrong?
Regards,
Jayee
I think you’re doing it right, but ServiceNow has been changing how this works so much that it’s hard to know what should or shouldn’t work. You could try a floating point decimal field and see if that works better. Otherwise you’ll just need to talk to ServiceNow support.
Hi Mark,
Thanks for responding. There is a type called ‘Floating Point Number’. I have not used this data type before. I had created a new field with this data type, but I do not understand how to restrict the decimal places in it. Can you tell me how to restrict the points after decimal in these type of fields?
Regards,
Jayee
I tried to do this in Helsinki but for some reason it does not work. I have put Max Length as 15 and scale=4 attribute but for some reason it only goes to 2 decimal place. Any suggestions?
Looks like the default value of max length for Decimal type fields is 18 in Helsinki version.
Use
Max length: “24” – without quotes (18 + 6)
Attributes: “scale=6” – without quotes
Works for me, tried on multiple fields.
Please increase Max length gradually from 18 to 21 and then to 24 keeping the scale fixed at 6.
Thank you Tanay!
There seems to be no logic in it but it’s exactly what worked for me – decimals stayed at 2 until I gradually increased max lenght :).