You need to sign in to do that
Don't have an account?
simon chao
Is there a way to round or truncate a number in lightning component so the decimal doesn't show?
How can i round or truncate off the decimal? I don't want the decimal to show. If a user input 1.5 I want it to show either 2 or 1 so either round up or truncate off the decimal, either one works.
Right now I have:
<lightning:input type="number" value="{!v.customNumber__c}"/>
Any help is greatly appreciated, thank you.
Right now I have:
<lightning:input type="number" value="{!v.customNumber__c}"/>
Any help is greatly appreciated, thank you.
All Answers
i dnt think so there is no ROUND function in lightning ...
<input type="text"
onblur="extractNumber(this,0,false);" onkeyup="extractNumber(this,0,false);" onkeypress="return blockNonNumbers(this, event, false, false);" />
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
function extractNumber(obj, decimalPlaces, allowNegative)
Hi ,
If you only want numbers , you can use ASCII codes to omit the input for other keys.
something like:
onkeydown="{!c.numberCheck}" // check the key press event.
//in controller.
numberCheck: function(component, event, helper){
if((event.keyCode>=48 && event.keyCode<=57 ) || event.keyCode==08){
}else{
event.preventDefault();
}
}
regards.