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!

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

    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.

  • Suggested answer
    RE: How to restrict user in entering decimal values for a whole number field without rounding off

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans