PDA

View Full Version : Show all the decimals values in a display field



blasrhr
20 Jul 2012, 12:35 PM
Hi there:
I have search the web about this with no luck so I just hope somebody can help me. I have values coming from a database with the exact format I need to show including decimal values but when I show then in a display field or text field, if there are not significative decimal values, it just trim them.
For instance (just in case my English is not clear):
My value is 10.0000
The value showing is 10.

I want the exact value coming from the database to show. I assume that's doable, I just don't know how.

Thanks in advance... Blas

Ex_Soft
20 Jul 2012, 1:36 PM
toFixed() (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number/toFixed)?

blasrhr
20 Jul 2012, 2:27 PM
Thanks for your reply but my problem is that I don't know how many digits after the decimal point will come from the database as I need to use it for every numeric field in my forms so I was just wonder if there is any global flag or something of that sort where I can say "respect the values after the decimal point" and it just leave the values as they are

suzuki1100nz
20 Jul 2012, 2:56 PM
Hi blas,

can you post some code? when I set the value on a display field to 10.00000 it displays it as 10.00000 it doesn't drop the zeros.
Are you sure the displayfield is truncating the value

blasrhr
23 Jul 2012, 7:24 AM
Hi suzuki1100nz:
Thanks for your reply. The code I'm writing is a little complex so to be sure were the problem was I took a code from Extjs 4 examples and change it a little bit (the original code is in examples/form/absform.js). I played with the values in the display field, but if I put something like 1.000 it drops all the zeros. This is the code:


/*


This file is part of Ext JS 4


Copyright (c) 2011 Sencha Inc


Contact: http://www.sencha.com/contact


GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.


If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.


*/
Ext.require([
'Ext.form.*',
'Ext.layout.container.Absolute',
'Ext.window.Window'
]);


Ext.onReady(function() {
var form = Ext.create('Ext.form.Panel', {
layout: 'absolute',
url: 'save-form.php',
defaultType: 'textfield',
border: false,


items: [{
fieldLabel: 'Send To',
fieldWidth: 60,
msgTarget: 'side',
allowBlank: false,
value:1.000,
allowDecimals: true,
x: 5,
y: 5,
name: 'to',
xtype: 'displayfield',
anchor: '-5' // anchor width by percentage
}, {
fieldLabel: 'Subject',
fieldWidth: 60,
x: 5,
y: 35,
name: 'subject',
anchor: '-5' // anchor width by percentage
}, {
x:5,
y: 65,
xtype: 'textarea',
style: 'margin:0',
hideLabel: true,
name: 'msg',
anchor: '-5 -5' // anchor width and height
}]
});


var win = Ext.create('Ext.window.Window', {
title: 'Resize Me',
width: 500,
height: 300,
minWidth: 300,
minHeight: 200,
layout: 'fit',
plain:true,
items: form,


buttons: [{
text: 'Send'
},{
text: 'Cancel'
}]
});


win.show();
});

Regards.... Blas