Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET format specifier for scientific notation with mantissa between 0 and 1

I am working with a Fortran program that expects floating point numbers to be input using Fortran's E format specifier, which is scientific notation, except the mantissa must be between 0 and 1. So instead of:

"3147.3" --> "3.1473E3",

it needs

"3147.3" --> "0.31473E4".

I am unable to modify the Fortran program, as it works with a few other programs that are also particular.

It would appear that the C# E format string would give me the former. Is there any simple way to achieve the latter in C#?

like image 216
davidtbernal Avatar asked Sep 01 '25 16:09

davidtbernal


1 Answers

You could specify a custom format like so.

var num = 3147.3;
num.ToString("\\0.#####E0"); // "0.31473E4"
like image 127
Jeff Mercado Avatar answered Sep 04 '25 06:09

Jeff Mercado