ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Andrey Rybak <ra@iop.kiev.ua>
To: ALT Linux Community <community@lists.altlinux.org>
Subject: Re: [Comm] c language question
Date: Sat, 04 Nov 2006 19:44:54 +0200
Message-ID: <454CD196.2040809@iop.kiev.ua> (raw)
In-Reply-To: <e12fd2db0611040818h3f17117n98b0deda9270dacf@mail.gmail.com>

Eugene Ostapets wrote:
> 04.11.06, Andrey Rybak<ra iop.kiev.ua> написал(а):
>   
>> Привет, коммунити!
>> Извините за оффтоп.
>> Стоит задача (стандартная должно быть) преобразовывать строки  вида
>> "0.ab" в целое число ab.
>> Вероятно, я плохо понимаю Си , но самый прямой метод будет выглядеть так:
>>       1 #include<stdio.h>
>>       2 #include<stdlib.h>
>>       3 int main(){
>>       4         const char* a = "0.16";
>>       5         printf("%d",(int)(100*atof(a)));
>>       6         return 0;
>>       7 }
>>     
> Плохо понимаете... Почитайте как храняться дробные числа... А для
> решения задачи смотрите man round, man rint
>   
они округляют только в заданном направлении, т.е. надо еще направление
округления задавать. (Или atof гарантированно возвращает, в данном
примере, либо .16 либо 15.99999... ? Тогда с дирекшионом проблем нет)
И чем эти функции отличаются от ceil & floor? Опять-таки не избежать
явного приведения типов (int)
Это я к тому - а что ж я плохо понимаю тогда?


  parent reply	other threads:[~2006-11-04 17:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-04 16:14 Andrey Rybak
2006-11-04 16:18 ` Eugene Ostapets
2006-11-04 17:39   ` Хихин Руслан
2006-11-04 17:59     ` Eugene Ostapets
2006-11-04 18:41       ` Хихин Руслан
2006-11-04 18:55         ` Michael Holzman
2006-11-04 19:17           ` Хихин Руслан
2006-11-04 20:32             ` Michael Holzman
2006-11-04 17:44   ` Andrey Rybak [this message]
2006-11-04 17:53     ` Eugene Ostapets
2006-11-04 18:24       ` Andrey Rybak
2006-11-04 18:30         ` Eugene Ostapets
2006-11-04 18:51           ` Andrey Rybak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=454CD196.2040809@iop.kiev.ua \
    --to=ra@iop.kiev.ua \
    --cc=community@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git