function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
simon chaosimon 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.
 
Best Answer chosen by simon chao
simon chaosimon chao
i ended up using ui:input instead of lightning:input. thanks everyone for your help 

All Answers

Complementary ComplementaryOneComplementary ComplementaryOne
sadfsa
prest nandprest nand
 prestnand@gmail.comprestnand@gmail.com
Raj VakatiRaj Vakati
You can do it in javascript controlle before setting it to the value 


i dnt think so there is no ROUND function in lightning ... 

 
simon chaosimon chao
The below will not allow negative or decimal number. Is there a way to traslante this into lighting component?

<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)
Balagopal GBalagopal G

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.

simon chaosimon chao
i ended up using ui:input instead of lightning:input. thanks everyone for your help 
This was selected as the best answer