# Nf() as text() parameter?

**URL:** https://discourse.processing.org/t/nf-as-text-parameter/23743
**Category:** Processing for Pi
**Created:** [September 8, 2020, 4:26pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743 "2020-09-08T16:26:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![joepekoe](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joepekoe](https://discourse.processing.org/u/joepekoe)
#### Post date: [September 8, 2020, 4:26pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/1 "2020-09-08T16:26:06Z")

</div>

I am developing code using Processing 3.5.4 on PC, exporting to Linux, copying exported files from armv6hf to Rpi Buster on Rpi 2 hardware. Since nf() returns a string, or at least I thought it did, I’m curious why the following code is not displaying 35678

float x = 35678.234;  
text( nf(x,0,0), 200, 200 );

The program displays 35678.234. The only way I can display a whole number is by casting the float into an int variable.

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 8, 2020, 4:51pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/2 "2020-09-08T16:51:08Z")

</div>

I can’t get it to display anything but the whole number using nf(number, 0, 0). Regardless of storing it in a string or not.

This worked for me:  
`text(nfs(x,0,-1), 200, 200 );`

---

<div class="post-metadata">

### Author: ![joepekoe](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joepekoe](https://discourse.processing.org/u/joepekoe)
#### Post date: [September 8, 2020, 5:37pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/4 "2020-09-08T17:37:45Z")

</div>

```auto
float f1 = 999.999;
String S1 = "this";
int x1 = 0;

void setup()
{
  size(800,400);
  background(0);
}

void draw()
{
    text(nf(f1,0,0),400,200);

    S1 = nf(f1,0,0);
    text(S1,400,220);

    x1 = (int)f1;
    text(x1,400,240);
}

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/adb6fe00d0cff90becaac3770265bf4f9ea11db7.png)

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 8, 2020, 9:10pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/5 "2020-09-08T21:10:16Z")

</div>

I get the same result.

Apparently, nf() also rounds the number depending on number of significant digits shown.

```auto
float f1 = 999.789;

String S1;
int x1 = 0;

void setup()
{
  size(200,200);
}

void draw()
{
  background(0);

  text(nf(f1,0,0),50,50);

  S1 = nf(f1,0,2);
  text(S1,50,70);

  S1 = nf(f1,0,-1);
  text(S1,50,90);

  x1 = (int)f1;
  text(x1,50,120);
}

```

![nf problem](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/52c25cc8ade2059c30db1e87ae3a061e5f4bf336.png)

---

<div class="post-metadata">

### Author: ![joepekoe](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joepekoe](https://discourse.processing.org/u/joepekoe)
#### Post date: [September 8, 2020, 9:33pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/6 "2020-09-08T21:33:09Z")

</div>

Thanks for confirming. Looks like a bug to me based upon behavior contrary to documentation. Just wondering if documentation is out of date.

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 8, 2020, 9:36pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/7 "2020-09-08T21:36:58Z")

</div>

Yes, it does seem that the case of `nf(number, 0, 0)` and `nf(number, 0, -1)` is undocumented.

---

<div class="post-metadata">

### Author: ![joepekoe](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@joepekoe](https://discourse.processing.org/u/joepekoe)
#### Post date: [September 8, 2020, 10:09pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/8 "2020-09-08T22:09:03Z")

</div>

> [@joepekoe](#):
>
> I am developing code using Processing 3.5.4 on PC, exporting to Linux, copying exported files from armv6hf to Rpi Buster on Rpi 2 hardware.

I checked documentation page more closely and it states “The values for the **digits** and **right** parameters should always be positive integers.” So I’m guessing that means this function isn’t supposed to be used to create a whole number the way I’ve been attempting it. I’m assuming that means they don’t support negative numbers either, even though it works.

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 8, 2020, 10:30pm UTC](https://discourse.processing.org/t/nf-as-text-parameter/23743/9 "2020-09-08T22:30:41Z")

</div>

There’s also the [round()](https://processing.org/reference/round_.html) function for that btw.
