ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Set Value not pushing value after decimal

custom_script

#1

I am having field float type field named value and another field as answer. What I am doing is on inserting a float value let say, 14.00 , I am using set value to push that value to field answer. Right now what is happening is if I am inserting 14.00, only 14 is inserted (but I want 14.00 to be inserted). Similarly, if I insert 9.80 , I want 9.80 to be pushed but its 9.8 which is pushed. Any help how to achieve that because I want 2-decimal place value whether it has to be zero.

Also, I dont want to make my field as Data as there is validation that only float values can be inserted.


#2

In the field change its Precision
to 2


#3

Thats not pushing the real float value but pushing 14.00 as 14


#4

what type of the data in “answer” field ?


#5

Small Text


#6

when assigning value
a = 10.0
p = 2
s = ‘%.{0}f’.format§ % a
print s

or

try Decimal module

from decimal import Decimal
num1 = Decimal(‘10.000’)
str(num1)
‘10.000’

num2 = Decimal(‘10.00’)
str(num2)
‘10.00’


#7

My Bad :stuck_out_tongue: . Just used .toFixed(2) as:

frm.doc.value.toFixed(2);

and it worked like charm :slight_smile:


#8