Equivalent of fmodf in C#?

2.1k views Asked by At

In C++ C: Output: "1610612736"

#include <math.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    printf("%d\n", fmodf(5.6f, 6.4f));
    getchar();
}

In C#: Output: "5.6"

using System;

static class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(5.6f % 6.4f);
        Console.Read();
    }
}

Clearly not the same output. Suggestions?

2

There are 2 answers

2
Alexandre C. On BEST ANSWER

Try with printf("%f\n", fmodf(5.6f, 6.4f)) instead.

1
Martin York On

Correcting the decimal problem with fprintf()

#include <math.h>
#include <stdio.h>
#include <iostream>

int main(int argc, char** argv)
{
    std::cout << fmodf(5.6f, 6.4f) << std::endl;
    getchar();
}

Output 5.6