Работа с числами. Экспоненциальная запись.

LyzArd
Offline
Зарегистрирован: 08.01.2018

Доброго времени суток. Вопрос от новичка не судите строго. Допустим, получаем значения переменной float следующего вида 314000, 314, 0.000314, 0.00000314. Как можно преобразовать получающееся число в вид 3.14Е+5, 314E+00, 3.14Е-4, 3.14Е-6? На Википедии нашел, что это экспоненциальная запись, но в силу неопытности не знаю, как реализовать. Прошу помощи в реализации такой функции или информации по данному вопросу. За ранее спасибо!.

Logik
Offline
Зарегистрирован: 05.08.2014

LyzArd пишет:
На Википедии нашел, что это экспоненциальная запись,

Потрясен! Пойду выпю чегонить..

wdrakula
wdrakula аватар
Offline
Зарегистрирован: 15.03.2016

Logik пишет:

LyzArd пишет:
На Википедии нашел, что это экспоненциальная запись,

Потрясен! Пойду выпю чегонить..

За образование! ...Не чокаясь!

wdrakula
wdrakula аватар
Offline
Зарегистрирован: 15.03.2016
char* dtostre ( double  __val,
    char *  __s,
    unsigned char  __prec,
    unsigned char  __flags
  )    

The dtostre() function converts the double value passed in valinto an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.

Conversion is done in the format "[-]d.ddde±dd"where there is one digit before the decimal-point character and the number of digits after it is equal to the precision prec; if the precision is zero, no decimal-point character appears. If flagshas the DTOSTRE_UPPERCASE bit set, the letter 'E'(rather than 'e') will be used to introduce the exponent. The exponent always contains two digits; if the value is zero, the exponent is "00".

If flagshas the DTOSTRE_ALWAYS_SIGN bit set, a space character will be placed into the leading position for positive numbers.

If flagshas the DTOSTRE_PLUS_SIGN bit set, a plus sign will be used instead of a space character in this case.

The dtostre() function returns the pointer to the converted string s.

================================

На словах просили передать, что оно  в <stdlib.h> .....

 

ЕвгенийП
ЕвгенийП аватар
Offline
Зарегистрирован: 25.05.2015

wdrakula пишет:

За образование! ...Не чокаясь!

Уж лучше за букву "А".

LyzArd
Offline
Зарегистрирован: 08.01.2018

Спасибо большое, помогло!