Controlling decimal field places

//Controlling decimal field places

Controlling decimal field places

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.

Decimal Places

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.

Decimal dictionary attributes

By | 2018-07-09T14:59:53+00:00 October 31st, 2012|Categories: System Definition|Tags: , |23 Comments

About the Author:

Mark has worked in the IT industry since 2002 and with ServiceNow since 2007. He is the founder and creator of SN | Guru and the co-founder of Crossfuze, one of the worlds leading ServiceNow consulting partners. Prior to co-founding Crossfuze, he worked for ServiceNow as a Senior Architect on the Professional Services team. He has personally led dozens of successful implementations encompassing every part of the ServiceNow platform. He is also responsible for designing and developing groundbreaking ServiceNow solutions and best practices in the form of various applications, turnkey solutions, and integrations during his tenure at ServiceNow, Crossfuze and, of course, SN | Guru. These solutions are used today by ServiceNow administrators and consultants alike in hundreds of ServiceNow instances around the world!

23 Comments

  1. Vanessa Loggins November 1, 2012 at 9:25 am - Reply

    Thank you so much for posting this. This is one of many of your articles that have helped me.

    • Mark Stanger November 1, 2012 at 12:29 pm - Reply

      I’m glad it helped! Please keep me in mind if you need consulting help in the future :).

    • Agree August 19, 2016 at 3:56 pm - Reply

      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

  2. Jim Pisello November 1, 2012 at 12:25 pm - Reply

    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”.

    • Mark Stanger November 1, 2012 at 12:30 pm - Reply

      Thanks Jim. I’m glad it’s documented now so I won’t have to remember the secret in the future :).

  3. Travis Castleman July 19, 2013 at 8:03 am - Reply

    Was trying to not truncate a trailing zero and this did not work for that. Any other solutions?

  4. Travis Toulson September 16, 2013 at 11:56 am - Reply

    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?

  5. genna February 28, 2014 at 6:46 am - Reply

    does not work. it actually rounds off my decimals which is crazy!

    • Mark Stanger February 28, 2014 at 7:02 am - Reply

      Give it a test in a ServiceNow demo instance. It works there exactly as I’ve described here.

  6. Nathan C May 2, 2014 at 4:15 am - Reply

    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)

    • Mark Stanger May 2, 2014 at 7:46 am - Reply

      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.

  7. Gary Opela November 21, 2014 at 9:57 am - Reply

    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.

  8. Robert Scott October 16, 2015 at 7:59 am - Reply

    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.

  9. Bhushan Salsekar March 3, 2017 at 5:08 am - Reply

    I have tried this but not able to resolve my issue. Can you please suggest.
    Thanks

    • Mark Stanger March 3, 2017 at 12:20 pm - Reply

      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.

  10. Bhushan Salsekar March 3, 2017 at 5:17 am - Reply

    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

  11. Jayee Chakrabarti March 17, 2017 at 8:25 am - Reply

    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

    • Mark Stanger March 17, 2017 at 9:05 am - Reply

      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.

  12. Jayee Chakrabarti March 20, 2017 at 7:24 am - Reply

    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

  13. Max Albanese September 28, 2017 at 11:57 am - Reply

    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?

  14. Tanay Bedia June 18, 2018 at 3:47 am - Reply

    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.

  15. Tanay Bedia June 18, 2018 at 4:31 am - Reply

    Please increase Max length gradually from 18 to 21 and then to 24 keeping the scale fixed at 6.

    • Martyna July 26, 2018 at 6:49 am - Reply

      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 :).

Leave A Comment