web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to restrict user in entering decimal values for a whole number field without rounding off

(1) ShareShare
ReportReport
Posted on by 37

Hello All,

I am working on Dynamics 365 v9 onpremise. I need a number field which accepts only numbers without any decimals / float number. For this, I have created a field with data type "Whole number", the issue we identified is when I enter "11.6", the system is rounding off the number and getting displayed as 12. I want to restrict the user in entering the decimal numbers.
I have tried to register onchange event for this field to restrict the user in entering decimals, but unfortunately the function is getting triggered after the value getting round-off.
Could anyone suggest on how to restrict a whole number field in entering only digits from 0 to 9,

Many Thanks in Advance!

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Sneha,

    There is no straightforward way to enter number without rounding off, but you can create two fields and use Math.trunc() function to achieve it.

    Here are steps.

    1.create two fields. (one is whole number data type, another is decimal number data type)

    If you need, you can set whole number filed is read-only.

    pastedimage1599460400218v1.png

    2.Js code.

    function setNumber(executionContext) {
        var formContext = executionContext.getFormContext();
        var oriNumber = formContext.getAttribute("new_testnum").getValue();
        var number=Math.trunc(oriNumber);
        if(oriNumber!=null)
        {
        Xrm.Page.getAttribute("new_testnumber").setValue(number);
        }
    }

    Add the JS code as web resource to OnChange event.

    3.Test

    When I fill ‘testnum’ field with value ’11.6’, the ‘testnumber’ field will be filled with ‘11’.

    pastedimage1599460411263v2.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Community Member Profile Picture
    on at

    Hi Partner,

    Has the problem been solved? Any updates?

    Please click Yes under "Did this answer your question?" to close this thread.

    pastedimage1599647708416v1.png

    Thanks. 

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans