6

我正在尝试将 gps 从字符串读取到我的 Arduino 上的浮点数。该字符串可以很好地处理所有数字,但是当我将它划分为浮点数时,我丢失了 4 个数字。这是我的代码:

gpsStrings[0].replace(".", "");
lat = gpsRawData[0].toFloat();
lat = lat / 1000000.0;

在仍然有小数点的字符串上使用 .toFloat 会产生相同的结果,小数点后只有两个数字。

示例编号:

42427898 :: 42.43 - what happens
42427898 :: 42.427898 - what I want to happen
4

2 回答 2

5

好吧我错了,默认的打印功能只使用两位精度。所以我不得不在声明中添加我想要的数字。

print(lat, 20);

将在串行监视器上给出 20 位精度,其中

print(lat)

只给了两个。

于 2012-08-23T13:55:46.303 回答
0

您想使用 Double 而不是浮点数。

有关详细信息,请参阅http://en.wikipedia.org/wiki/Primitive_data_typehttp://en.wikipedia.org/wiki/Double_precision#Double-precision_examples

于 2012-08-22T14:49:30.000 回答