1

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)}
Ken White
  • 123,280
  • 14
  • 225
  • 444
Natalia G
  • 11
  • 1

1 Answers1

0

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)}
carlosdafield
  • 1,479
  • 5
  • 16