# Floating Point

**URL:** <https://www.ruby-forum.com/t/floating-point/226934>\
**Category:** NGINX\
**Created:** [February 26, 2013, 10:33am UTC](https://www.ruby-forum.com/t/floating-point/226934 "2013-02-26T10:33:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aparna\_Bhat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@Aparna\_Bhat](https://www.ruby-forum.com/u/Aparna_Bhat)\
**Post date:** [February 26, 2013, 10:33am UTC](https://www.ruby-forum.com/t/floating-point/226934/1 "2013-02-26T10:33:39Z")

</div>

Hi,

I am working on a module for load balancing. I have to make use of the  
type  
float. Can anyone please tell me if there is any nginx specific data  
type  
for float such as the one that exists for int (ngx\_int\_t). I would also  
like to know how to write the float value to the logs. The type %f  
prints  
only the integer portion of the float value.

Thank you in advance.

With Regards,  
Aparna.

---

<div class="post-metadata">

**Author:** ![Aparna\_Bhat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@Aparna\_Bhat](https://www.ruby-forum.com/u/Aparna_Bhat)\
**Post date:** [February 26, 2013, 10:57am UTC](https://www.ruby-forum.com/t/floating-point/226934/2 "2013-02-26T10:57:37Z")

</div>

Default precision for %f is 6 digits (ISO C99)  
what’s your test case ?

---

<div class="post-metadata">

**Author:** ![Aparna\_Bhat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@Aparna\_Bhat](https://www.ruby-forum.com/u/Aparna_Bhat)\
**Post date:** [February 26, 2013, 11:09am UTC](https://www.ruby-forum.com/t/floating-point/226934/3 "2013-02-26T11:09:54Z")

</div>

On Feb 26, 2013, at 13:32 , Aparna Bhat wrote:

> I am working on a module for load balancing. I have to make use of the type  
> float. Can anyone please tell me if there is any nginx specific data type for  
> float such as the one that exists for int (ngx\_int\_t). I would also like to know  
> how to write the float value to the logs. The type %f prints only the integer  
> portion of the float value.

There is no special float integer type in nginx.  
nginx %f format is for double, so you have to cast float to double in  
ngx\_sprintf().  
To print fractional portion you should use “%.3f”, the maximum supported  
format is “%18.5f”.
