EasyUI Forum
May 15, 2024, 09:59:08 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Numberbox format to 5 or 5.1 not 5.0 [SOLVED]  (Read 10858 times)
dayaners
Newbie
*
Posts: 16


View Profile
« on: May 22, 2014, 06:27:30 AM »

Good day, I would use the number box to create student grades in high school, however the number rounds to integer. Need to be allowed to place or integer (5) when he put the precision 2 rounds (5.0) but I need to stay (5) or (5.2).
Could someone help me? sorry for my bad english.

Code:
 {field:'ano1',title:'ANO 1',width:70,align:'center',editor:{type:'numberbox'}},
« Last Edit: May 22, 2014, 10:59:11 AM by dayaners » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: May 22, 2014, 07:55:16 AM »

The numberbox takes the 'precision' property that can be used to display the number precision after the decimal separator.
Code:
{field:'ano1',title:'ANO 1',width:70,align:'center',
  editor:{
    type:'numberbox',
    options:{
      precision:1
    }
  }
},
Logged
dayaners
Newbie
*
Posts: 16


View Profile
« Reply #2 on: May 22, 2014, 08:04:18 AM »

when  i put precision 1:

the value 5.1 stay 5 and when put 5.5 they go to 6...

i need put 5.1 or 5.2 and 5 only
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 on: May 22, 2014, 08:28:07 AM »

If you want to do some special conversions, you have to customize the 'formatter' and 'parser' functions. The code below achieves how to round a number downwards to the nearest integer.
Code:
{field:'ano1',title:'ANO 1',width:70,align:'center',
  editor:{
    type:'numberbox',
    options:{
formatter:function(v){
return v;
},
parser:function(s){
var v = parseFloat(s);
return isNaN(v)?'':Math.floor(v);
}
    }
  }
},
Logged
dayaners
Newbie
*
Posts: 16


View Profile
« Reply #4 on: May 22, 2014, 10:29:09 AM »

this is the default, I need it to stop rounding.
Logged
dayaners
Newbie
*
Posts: 16


View Profile
« Reply #5 on: May 22, 2014, 10:58:07 AM »

got Cheesy thanks a lot!

Code:
{field:'ano1',title:'ANO 1',width:70,align:'center',editor:{type:'numberbox',options:{
formatter:function(v){
return v;
},
parser:function(s){
var v = parseFloat(s);
return isNaN(v)?'':Math.abs(v);
}}}
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!