小编ami*_*igo的帖子

C# - 字符串到数字

我再次回到我的一个问题和疑问.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

namespace compare_string
   {
     class Program
     {
        static void Main(string[] args)
        {
            string str1 = "85.8500000000000";
            string str2 = "85.85";
            double num1 = Convert.ToDouble(str1);
            double num2 = Convert.ToDouble(str2);
            if (num1 != num2)
            {
                 Console.WriteLine("Unequal");
            }
            else {
                 Console.WriteLine("Equal");
            }
             Console.ReadKey();
         }
    }
  }
Run Code Online (Sandbox Code Playgroud)

为什么要说两个数字是不相等的?提前致谢!

c#

0
推荐指数
2
解决办法
1236
查看次数

在函数中更改数组不会改变它在main中的值

我尝试用-0.8和0.8之间的随机数填充矢量(我必须分配).我的问题是为什么在main函数中我调用函数setvector()不返回向量而我仍然用零初始化?非常感谢.在这里我做了什么

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void allocate(double **a, int size) {
    *a = malloc(size);
}

double setvector(double *v){
    int i, seed, send_size;

    send_size = 10;

    allocate(&v, send_size * sizeof(double)); // allocate memory for the vector
    seed = time(NULL);
    srand(seed);
    for (i = 0; i < send_size; i++)
    {
        v[i] = 1.6*((double) rand() / (double) RAND_MAX) - 0.8;
    }
    printf("Inside function the vector is:\n\n");
    for (i = 0; i < 10; i++)
    {
        printf("The %d element has the random …
Run Code Online (Sandbox Code Playgroud)

c pointers

0
推荐指数
1
解决办法
138
查看次数

标签 统计

c ×1

c# ×1

pointers ×1