完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我在把数字从“字符串格式”转换成“浮点数字”时遇到了问题。为了这个目的,我使用“ATOF”函数。我使用了代码:但是在变量“n”中存储的是i=11123535。它在点之后是3位数。但是我希望它精确地存储,即“n=1”。1.123456“有没有比使用函数更好的方法?
以上来自于百度翻译 以下为原文 Hi all, I have problem in converting the numbers from "string format" to "floating point numbers". I am using "atof" function for that purpose. I used the code: signed float n; char inf="11.123456" n=atof(inf); But what is storing in the variable "n" is n=11.123535 It is correct up to 3 digits after the point. But I want it to store accurately i.e., "n=11.123456" Is there any better way than using atof function |
|
相关推荐
5个回答
|
|
XC8的浮动变量的精度(?)编译器就是这样的。您不能只按需要添加小数位数,这不是Atof函数的问题。从HTTP://www-MyCHIP.COM/FUMMS/M96562.ASPXO中获取,如果您还没有使用32位浮点,那么这可能会给您更精确的一点。锡安。解决方案取决于你想用这些数字做什么,例如,你真的需要浮点…P.S.你解决了SIM808的电平移位问题吗?
以上来自于百度翻译 以下为原文 The precision for float variables of your XC8 (?) compiler is like that. You cannot just add fractional digits as you want, and this is not a problem of the atof function. taken from http://www.microchip.com/forums/m966542.aspx So if you do not already use 32 bit floats, then that might give you a littlebit more precision. But think about whether you really need more precision. The solution depends on what you are trying to do with these numbers, e.g. do you really need floating point ... P.S. Did you solve your level shifter problem for SIM808 ? |
|
|
|
请注意,切换到32位浮点将导致更慢的代码。
以上来自于百度翻译 以下为原文 And Note that switching to 32bit floats will result in bigger slower code. |
|
|
|
如果浮点变量的大小和精度相似,则可以使用32位长,其中11.123456表示11123456。您可以获得6位数的精度值,达到4294(未签名)。可能有固定点数值类型,尽管可能不适用于PICS和XC8。我找到了这个20年的文档:http://www. Microchip .com /下载/Eng/NoppNo/0526E.PDFANHTTP://WW1.Microchip .com…/En/AppNodis/0617PDF.对于PIC24和PIC32有固定的例程:http://www. MicroChIP.COM/SWLabyWeb/Studio.ASPX?产品=固定%20点%20MaTys20LabyLaCube可能满足您的需求:http://www. McCHIP.COM/FUMMS/M801645.ASPXORT项目:http://885.n7.nabbul.com /浮点定点-TD89814HTMLhttp://www. PcList.COM/TeCfRe/MyCHIP/Mth/BasIC.HTM
以上来自于百度翻译 以下为原文 If your floating point variables are similar in size and precision, you might be able to use 32 bit long, where 11.123456 would be represented by 11123456. You can get 6 digit fractional precision for values up to 4294 (unsigned). There may be a fixed point numerical type, although perhaps not for PICs and XC8. I found this 20 year old document: http://ww1.microchip.com/downloads/en/AppNotes/00526e.pdf and http://ww1.microchip.com/.../en/AppNotes/00617.pdf There are fixed point routines for PIC24 and PIC32: http://www.microchip.com/SWLibraryWeb/product.aspx?product=Fixed%20Point%20Math%20Library Perhaps long double would meet your needs: http://www.microchip.com/forums/m801645.aspx Other items of interest: http://microcontrollers.2385.n7.nabble.com/Floating-point-fixed-point-td89814.html http://www.piclist.com/techref/microchip/math/basic.htm |
|
|
|
如果浮点变量的大小和精度相似,则可以使用32位长,其中11.123456表示11123456。您可以获得6位数的精度值,达到4294(未签名)。可能有固定点数值类型,尽管可能不适用于PICS和XC8。我找到了这个20年的文档:http://www. Microchip .com /下载/Eng/NoppNo/0526E.PDFANHTTP://WW1.Microchip .com…/En/AppNodis/0617PDF.对于PIC24和PIC32有固定的例程:http://www. MicroChIP.COM/SWLabyWeb/Studio.ASPX?产品=固定%20点%20MaTys20LabyLaCube可能满足您的需求:http://www. McCHIP.COM/FUMMS/M801645.ASPXORT项目:http://885.n7.nabbul.com /浮点定点-TD89814HTMLhttp://www. PcList.COM/TeCfRe/MyCHIP/Mth/BasIC.HTM
以上来自于百度翻译 以下为原文 If your floating point variables are similar in size and precision, you might be able to use 32 bit long, where 11.123456 would be represented by 11123456. You can get 6 digit fractional precision for values up to 4294 (unsigned). There may be a fixed point numerical type, although perhaps not for PICs and XC8. I found this 20 year old document: http://ww1.microchip.com/downloads/en/AppNotes/00526e.pdf and http://ww1.microchip.com/.../en/AppNotes/00617.pdf There are fixed point routines for PIC24 and PIC32: http://www.microchip.com/SWLibraryWeb/product.aspx?product=Fixed%20Point%20Math%20Library Perhaps long double would meet your needs: http://www.microchip.com/forums/m801645.aspx Other items of interest: http://microcontrollers.2385.n7.nabble.com/Floating-point-fixed-point-td89814.html http://www.piclist.com/techref/microchip/math/basic.htm |
|
|
|
谢谢大家,这个问题是通过设置32位浮点配置来解决的。我非常感谢你们的帮助。谢谢你的帮助。我用了一个上拉电路,它起作用了。现在,PIC18F480能够读取GSM的响应,并在LCDSmile中显示它:
以上来自于百度翻译 以下为原文 Thank you all. The problem is solved by setting 32 bit configuration for floating point. I really appreciate your help. And about "level shifter problem for SIM808" Yeah it is solved. Thank you for your help. I used a pull-up circuit for it.It worked. Now the PIC18f4580 is able to read the response from the GSM and is displaying it in the LCDSmile: |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
733浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 06:18 , Processed in 1.121874 second(s), Total 84, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号