# Want to convert string to int

**URL:** <https://discourse.processing.org/t/want-to-convert-string-to-int/29387>\
**Category:** Beginners\
**Created:** [April 15, 2021, 4:11pm UTC](https://discourse.processing.org/t/want-to-convert-string-to-int/29387 "2021-04-15T16:11:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)\
**Post date:** [April 15, 2021, 4:11pm UTC](https://discourse.processing.org/t/want-to-convert-string-to-int/29387/1 "2021-04-15T16:11:16Z")

</div>

Hello, I’m trying to make a program to basically calculate COVID risk off the user’s age. Right now, I coded for the user to be able to type their age, but I want the string they type to be converted to an int when they press enter.

```auto
PFont font;
String typedAge = "";
int userAge;
void setup(){
  size(300,300);
  font = createFont("Arial",20);
}

void draw(){
  background(255);
  println(userAge);
  textFont(font);
  fill(0);
  textAlign(CENTER);
  text("Type in Age", width/2, height/2);
  text("Click Enter to Save", width/2, height/2 + 25);
  text("Age: " + typedAge, width/2 - 25, height/2 + 50);
}

void keyPressed(){
  if(key == '\n'){
   // this is where the conversion would happen, saving typedAge to userAge
  } else{
    typedAge = typedAge + key;
  }
}

```

---

<div class="post-metadata">

**Author:** ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)\
**Post date:** [April 15, 2021, 4:19pm UTC](https://discourse.processing.org/t/want-to-convert-string-to-int/29387/2 "2021-04-15T16:19:58Z")

</div>

Nevermind, I used userAge = int(typedAge);, worked well.
