locked
Standard way to save and fetch the exponential value from and to the database RRS feed

  • Question

  • User-1569093213 posted

    Hello all,

    I am using dot net core and react js .I want to store the exponential value into database so what should be the standard way to do so.

    Currently my exponential value is going from front end correctly but after saving it into database it is getting converted into float as I am using float datatype for saving exponential value..but after fetching it from database it is getting wrong value ? so want suggestion like

    1] what datatype should I keep for database column for storing exponential value?

    2] Do I need to convert float value into exponential into backend?

    The thing is that if I store 1.2345E+10 value then after conversion it is getting like 1.23E+10..

    How can I do that?Please give some suggestion.

    T

    Thursday, June 18, 2020 4:57 AM

All replies

  • User409696431 posted

    You asked this question and got an answer:

    https://forums.asp.net/t/2167163.aspx?How+to+store+exponential+value+in+sql+server

    The syntax for custom string formatting for exponents (with format specifier e or E) is found on this page: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    If it is not working, you need to show the code you are using.

    Thursday, June 18, 2020 5:42 AM
  • User475983607 posted

    1] what datatype should I keep for database column for storing exponential value?

    Use a type large enough to hold the value.  It is important to understand you are using symbols to represent the same number.  the following two values are equal!

    12300000000 = 1.23E+10

    2] Do I need to convert float value into exponential into backend?

    The best I can guess is you are struggling with significant figures.  This is a math question or application requirements question not an ASP.NET support question.  It's up to you or the folks requesting the application to determine the number of significant figures.  If you decide that 5 decimal places is a requirement when entering a exponent format then it is up to you to write validation code to guide the user.   

    Anyway, if you want to show 5 decimal places after the decimal then change the string format accordingly.

    decimal num = 12300000000m;
    Console.WriteLine(string.Format("{0:0.#####E+00}", num));
    
    num = 12345600000m;
    Console.WriteLine(string.Format("{0:0.#####E+00}", num));

    Results

    1.23E+10
    1.23456E+10

    Keep in mind, C# string formats are openly published.    This information is not hidden.

    Thursday, June 18, 2020 12:20 PM