15,995,072 members
Home / Discussions / C#

# C#

 Re: c# Nitin S26-Dec-22 18:10 Nitin S 26-Dec-22 18:10
 Re: c# RedDk27-Dec-22 8:54 RedDk 27-Dec-22 8:54
 convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base Sakhalean23-Dec-22 23:48 Sakhalean 23-Dec-22 23:48
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base OriginalGriff24-Dec-22 0:29 OriginalGriff 24-Dec-22 0:29
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base Sakhalean25-Dec-22 4:52 Sakhalean 25-Dec-22 4:52
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base BillWoodruff24-Dec-22 18:37 BillWoodruff 24-Dec-22 18:37
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base Sakhalean24-Dec-22 22:46 Sakhalean 24-Dec-22 22:46
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base trønderen24-Dec-22 23:13 trønderen 24-Dec-22 23:13
 BillWoodruff wrote:ask yourself what numeric types it makes sense to convert the values you describeWhy wouldn't it make sense? If b >= 10, you obviously have to define 'digits' for 10+; using A-Z for 10-36 is quite common. Equally obvious: The result of conversion must be treated as a digit string; there is no other way to handle, say, a base 13 number in a binary computer. In decimal, the digits to the left of the decimal point give the number of ones, then number of tens, then ten**2s, ten**3s, ten**4s, ... To the right of the decimal point digits give the number of 1/10s, then the number of 1/(10**2)s, 1/(10**3)s, 1/(10**4)s, ... For base b, the digits to the left of the point give the number of ones, then number of bs, then b**2s, b**3s, b**4s, ... To the right of the point, digits give the number of 1/bs, then the number of 1/(b**2)s, 1/(b**3)s, 1/(b**4)s, ... I guess it would be somewhat confusing to call it a decimal point, though. "Octal is just like decimal ... if you are missing two fingers" (Tom Lehrer) To the OP: I would have split the number on the point, treating the whole and the fractional parts separately, converting then to binary integers, and then iterated each over a divide/remainder down to zero. Note that for the fractional part, you must set a reasonable limit for the number of digits - in, say, base 13 you cannot represent 879/1000 (that is from your first example) as any finite series of fractional digits f1/13 + f2/169 + f3/2197 + ... + fn/(13**n), except for a few special cases. (That goes for decimal .879 or .345 as well; they are not represented by those exact values in double format.)
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base BillWoodruff25-Dec-22 4:15 BillWoodruff 25-Dec-22 4:15
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base Sakhalean25-Dec-22 4:50 Sakhalean 25-Dec-22 4:50
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base BillWoodruff25-Dec-22 5:13 BillWoodruff 25-Dec-22 5:13
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base trønderen25-Dec-22 11:17 trønderen 25-Dec-22 11:17
 Re: convert double with decimal places to any base in C# example : 19.879 to any base or -19.345 to any base Sakhalean25-Dec-22 14:06 Sakhalean 25-Dec-22 14:06
 EF Core 6 Repository Pattern Kevin Marois23-Dec-22 9:11 Kevin Marois 23-Dec-22 9:11
 Re: EF Core 6 Repository Pattern Richard Deeming5-Jan-23 0:02 Richard Deeming 5-Jan-23 0:02
 Re: EF Core 6 Repository Pattern Kevin Marois5-Jan-23 6:46 Kevin Marois 5-Jan-23 6:46
 Re: EF Core 6 Repository Pattern Richard Deeming5-Jan-23 22:41 Richard Deeming 5-Jan-23 22:41
 Re: EF Core 6 Repository Pattern Kevin Marois6-Jan-23 5:38 Kevin Marois 6-Jan-23 5:38
 Re: EF Core 6 Repository Pattern Richard Deeming8-Jan-23 21:35 Richard Deeming 8-Jan-23 21:35
 Mysql database freezes with Visual Sudio C# Member 1405587918-Dec-22 5:44 Member 14055879 18-Dec-22 5:44
 Re: Mysql database freezes with Visual Sudio C# RedDk18-Dec-22 10:10 RedDk 18-Dec-22 10:10
 Re: Mysql database freezes with Visual Sudio C# Dave Kreskowiak18-Dec-22 11:20 Dave Kreskowiak 18-Dec-22 11:20
 Re: Mysql database freezes with Visual Sudio C# Richard Deeming18-Dec-22 21:08 Richard Deeming 18-Dec-22 21:08
 Multi-threaded debugging Richard Andrew x6411-Dec-22 6:12 Richard Andrew x64 11-Dec-22 6:12
 Re: Multi-threaded debugging Gerry Schmitz11-Dec-22 7:09 Gerry Schmitz 11-Dec-22 7:09
 Last Visit: 31-Dec-99 18:00     Last Update: 11-Sep-24 22:36 Refresh ᐊ Prev1...48495051525354555657 Next ᐅ