Exemplo n.º 1
0
int main()
{
	float f;
	char float_str[30];
	memset(float_str,0,30);
	printf("Please input a float.\n");
	scanf("%f",&f);
	float_to_str(float_str, f);
	printf("The string is:\n");
	puts(float_str);
	return 0;
}
Exemplo n.º 2
0
int main()
{
	float f;
	char s[100];
	printf("enter a float:\n");
	scanf("%f", &f);

	
	float_to_str(f, s);
	printf("float to string is: %s\n", s);

	return 0;
}
Exemplo n.º 3
0
/* render dashboard percent */
static void
render_percent (GDashModule * data, GDashRender render, int *x)
{
  WINDOW *win = render.win;
  GModule module = data->module;
  const GDashStyle *style = module_style;

  char *percent;
  int y = render.y, w = render.w, idx = render.idx, sel = render.sel;
  int len = data->perc_len + 3;

  if (data->module == HOSTS && data->data[idx].is_subitem)
    goto out;
  if (style[module].color_percent == -1)
    return;

  /* selected state */
  if (sel) {
    percent = float_to_str (data->data[idx].metrics->percent);
    draw_header (win, percent, "%*s%%", y, *x, w, HIGHLIGHT, len);
    free (percent);
  }
  /* regular state */
  else {
    wattron (win, A_BOLD | COLOR_PAIR (style[module].color_percent));
    if (data->max_hits == data->data[idx].metrics->hits)
      wattron (win, A_BOLD | COLOR_PAIR (COL_YELLOW));
    if (style[module].color_percent == COL_BLACK)
      wattron (win, A_BOLD | COLOR_PAIR (style[module].color_percent));

    mvwprintw (win, y, *x, "%*.2f%%", len, data->data[idx].metrics->percent);

    if (style[module].color_percent == COL_BLACK)
      wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_percent));
    if (data->max_hits == data->data[idx].metrics->hits)
      wattroff (win, A_BOLD | COLOR_PAIR (COL_YELLOW));
    wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_percent));
  }
out:

  *x += len + 1 + DASH_SPACE;
}
Exemplo n.º 4
0
int main ()
{
    float swatch;
    time_t sec;
    static char beat_text[] = "@";
    sec = time (NULL);
    /* Swatch time is based on CET (Central European Time) which is +1GMT.  NO DST bullshit either. */
    /* hence, the formula is basically epochtime in seconds + one hour in seconds */
    /* I specifically wanted "centibeats" hence the garbage with floats and 3 decimal places. */
    /* As I am a dumbshit at C, I will eventually make a commandline arg for this. */
    swatch = (float)(((sec + 3600) % 86400) * 1000) / 86400;
    printf ("@%06.3f\n", swatch);
    printf ("------\n");

	// Added by hailey in a format simular to that used on 
	// https://github.com/jerith/pebble-beapoch/blob/master/src/beapoch.c
	
    strcat(beat_text,float_to_str(swatch));
    printf(beat_text);


    return 0;
}
Exemplo n.º 5
0
int vprintf( const char *fmt, va_list arg )
{
    int character_count = 0;
    char temp_buf[64];

    if ( fmt == NULL )
        return -1;

    while ( *fmt )
    {
        if ( *fmt == '@' )
        {
            fmt++;

            // We don't handle any special formatting
            switch ( *fmt )
            {
            case '@':
                putc( '@' );
                break;

            case 'd':
                // Integer
                {
                    int int_arg = va_arg( arg, int );
                    char *c;

                    int_to_str( int_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 'f':
                // Float
                {
                    double float_arg = va_arg( arg, double );
                    char *c;
#ifdef PATCHED
                    float_to_str( float_arg, temp_buf, 64 );
#else
                    float_to_str( float_arg, temp_buf );
#endif

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;
            case 's':
               // string
               {
                    char *string_arg = va_arg( arg, char *);
                    while (*string_arg)
                    {
                        putc( *string_arg );
                        character_count++;
                        string_arg++;
                    }
              }
              break;
            case '\0':
                return -1;

            default:
                // Unknown
                return -1;
            }

            fmt++;
        }
        else
        {
Exemplo n.º 6
0
StringBuffer& StringBuffer::insert(size_t __pos,const double& __n)
{
	//m_cache_str.insert(__pos,Number::toString(__n));
	m_cache_str.insert(__pos,float_to_str(__n)) ;
	return *this;
}
Exemplo n.º 7
0
 std::string from(long double x)
 {
     return float_to_str(x);
 }
Exemplo n.º 8
0
 std::string from(float x)
 {
     return float_to_str(x);
 }
Exemplo n.º 9
0
int vprintf( const char *fmt, va_list arg )
{
    int character_count = 0;
    char temp_buf[64];

    if ( fmt == NULL )
        return -1;

    while ( *fmt )
    {
        if ( *fmt == '@' )
        {
            fmt++;

            // We don't handle any special formatting
            switch ( *fmt )
            {
            case '@':
                putc( '@' );
                break;

            case 'c':
                // single charß
                {

                    char c = (char )va_arg(arg, int);
                    putc(c);
                }
                break;
                
            case 'd':
                // Integer
                {
                    int int_arg = va_arg( arg, int );
                    char *c;

                    int_to_str( int_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 'x':
                // hex
                {
                    unsigned int int_arg = va_arg( arg, unsigned int );
                    char *c;

                    int_to_hex( int_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 'f':
                // Float
                {
                    double float_arg = va_arg( arg, double );
                    char *c;

                    float_to_str( float_arg, temp_buf );

                    c = temp_buf;
                    while ( *c )
                    {
                        putc( *c );
                        character_count++;
                        c++;
                    }
                }
                break;

            case 's':
                // String
                {
                    char *string_arg = va_arg( arg, char * );

                    while ( *string_arg )
                    {
                        putc( *string_arg );
                        character_count++;
                        string_arg++;
                    }

                }
                break;

            case '\0':
                return -1;

            default:
                // Unknown
                return -1;
            }

            fmt++;
        }
        else
        {
Exemplo n.º 10
0
void myprint_float(float num)
{
  u8 *str = float_to_str(num);
  myprint((const char*)str);
}