# Good practice: Reading floats from number input field

**URL:** <https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971>\
**Category:** URCap Development\
**Created:** [July 14, 2017, 7:09am UTC](https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971 "2017-07-14T07:09:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [July 14, 2017, 7:09am UTC](https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971/1 "2017-07-14T07:09:59Z")

</div>

When reading a floating point number from an InputTextField, it should be noted, that there can be different decimal notations, based on the users selection of language.  
English language would use dot-notation (e.g. `1.5`) where e.g. French would use comma-notation (e.g. `1,5`) - this is also the raw text that would be read from the input field using the `getText()` method.  
As URScript will need dot-notation for decimal separation, it is good practice to ensure that the number parsed will have this format.

This can e.g. be done in the following ways, depending on whether the input is desired as `float` or `String`.

```auto
float myFloatVal = NumberFormat.getInstance().parse(textInField).floatValue();
String textWithNumFormat = NumberFormat.getInstance().parse(textInField).toString();

```

---

<div class="post-metadata">

**Author:** ![anon23279734](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@anon23279734](https://forum.universal-robots.com/u/anon23279734)\
**Post date:** [June 19, 2018, 7:24am UTC](https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971/2 "2018-06-19T07:24:07Z")

</div>

Hi, I have a issue related with this topic. When I’m trying to read a float number with an InputTextField, just like in the Whip URCap sample, the simulator notifies me of an error. It can’t read numbers with decimal notations…

```
@Input(id="numanalog")
public void onNumanalogChange(InputEvent event){
	if(event.getEventType() == InputEvent.EventType.ON_CHANGE){

		Numero = Float.parseFloat(numanalog.getText());	
		// Se pone la variable analógica al valor leído
		VariableAO.setValue(Numero);

```

How can I read a float number from an InputTextField?  
“Numero” is a variable where I save the number read.

---

<div class="post-metadata">

**Author:** ![anon23279734](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@anon23279734](https://forum.universal-robots.com/u/anon23279734)\
**Post date:** [June 19, 2018, 7:29am UTC](https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971/3 "2018-06-19T07:29:33Z")

</div>

Sorry, I just realize how can I fix this. Thank you

---

<div class="post-metadata">

**Author:** ![anon82484413](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@anon82484413](https://forum.universal-robots.com/u/anon82484413)\
**Post date:** [November 28, 2018, 8:06am UTC](https://forum.universal-robots.com/t/good-practice-reading-floats-from-number-input-field/971/4 "2018-11-28T08:06:34Z")

</div>

I tried to make a function to just run it all through, just to be safe, but it isnt doing what I expect.

```
	private double returnSafeDouble(String input)
	{
		double output = 0;
		try
		{
			output = NumberFormat.getInstance().parse(input).doubleValue();
		}
		catch (ParseException e)
		{
			e.printStackTrace();
		}
		
		System.out.println("Converted " + input + " into " + Double.toString(output));
		
		return output;
	}

```

When I feed it 4.5, it returns 4.5, but when I feed it 4,5 it returns 45,0

![Udklip](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/1/17d963447e35bcccefbdeb243a47f13d55e84c4f.png)
