如何合并两个数字并将其存储在另一个数字之间

How to merge two numbers and store it in another with point in between them

我正在制作一个 C 程序,其中有两个数字 num1=11num2=98 。我希望他们将其存储在另一个数字中,例如 num3=11.98 11 到 98 之间的那一点很重要。这个怎么做。请帮忙,谢谢!

试试这个(假设 num1 和 num2 已经声明并赋值)

找到 num2 的长度并将其存储在变量中 "len2"

float num3 = (float)num1 + ((float)num2 / pow(10,len2));

下面的一些代码可能会解决您的问题。

float floatingNum = num2;
while(floatingNum > 1)
{
  floatingNum = floatingNum / 10;
}
float num3 = num1 + floatingNum;