The length and decimal places are only enforced when editing data via
the standard web UI. (i.e., Custom object | New field | Data type:
Number | Check the fields - length and decimal places)
Apex and API methods can actually save records with decimal places. This is true for standard and custom fields. Salesforce changes the display to match the definition, but they are stored in the database as inserted.
When the user sets the precision in custom fields in the Salesforce application, it displays the precision set by the user, even if the user enters a more precise value than defined for those fields. However, when you set the precision in custom fields using the API, no rounding occurs when the user retrieves the number field.
Define a custom number field, say, "Number." Give it length = 3, and
decimal places = 1. It might seem that this is done to restrict the
precision of the field to two decimal places. However, on the UI level
(on a standard edit page), if you try to type in, say, 237.631, it'll
round off 237.631 when you click "Save" and store it in the database
But if you then set a value via API, say 237.631, it'll be
stored in the database - and returned via API (e.g. SOQL query) - as
237.631. In fact , SFDC will let you store up to 24 decimal points via API, regardless of the decimal places provided in the field
definition. So you could save 237.123456789012345678901234.
This is completely working as designed and Salesforce kept the behavior so that it can be backward compatible.
Reference:- Data type number field does not store more numbers in decimal places than defined
Also, Introducing SOAP API