How to get a $ sign and a comma separator in TextInput?

Viewed 207

I am trying to figure out how to 1) get a comma separator and a $ when text is entered via TextInput and 2) also show $ and a comma separator for results when the function does calculation? Many thanks

Code example:

      import React, {useState} from 'react';
      const [Number1, Number1OnChange] = React.useState ();
      const [TotalSum,setTotalSum] = React.useState (0);

      function calcAllCalcs (){
         let TotalSum1=(parseInt(Number1) + parseInt(Number2)
            setTotalSum(TotalSum1);}

        return (
            <TextInput style = {styles.answer1}
            
            underlineColorAndroid = "transparent"
            placeholder = " Enter Number1 ..."
            autoCapitalize = "none"
            value={Number1} 
            onChangeText={Number1 => Number1OnChange(Number1)}
            numeric
            keyboardType={'numeric'}            
            />

          onPress={calcAllCalcs}>
          {TotalSum.toFixed(0)}
1 Answers

You have to make number1 the value in the textinput

      import React, {useState} from 'react';
      const [Number1, Number1OnChange] = React.useState ();
      const [TotalSum,setTotalSum] = React.useState (0);

      function calcAllCalcs (){
         let TotalSum1=`${number1}$`
            Number1OnChange(TotalSum1);}

        return (
            <TextInput style = {styles.answer1}
            
            underlineColorAndroid = "transparent"
            placeholder = " Enter Number1 ..."
            autoCapitalize = "none"
            value={Number1}  <--Change this to be number1 the thing you want to show
            onChangeText={Number1 => Number1OnChange(Number1)}
            numeric
            keyboardType={'numeric'}            
            />

          onPress={calcAllCalcs}>
          {TotalSum.toFixed(0)}
Related