Cast string to real (R4P).
use penf
type(string) :: astring
real(R4P) :: real_
logical :: test_passed(1)
astring = '3.4e9'
real_ = astring%to_number(kind=1._R4P)
test_passed(1) = real_==3.4e9_R4P
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
||
real(kind=R4P), | intent(in) | :: | kind |
Mold parameter for kind detection. |
The number into the string.
elemental function to_real_R4P(self, kind) result(to_number) !< Cast string to real (R4P). !< !<```fortran !< use penf !< type(string) :: astring !< real(R4P) :: real_ !< logical :: test_passed(1) !< astring = '3.4e9' !< real_ = astring%to_number(kind=1._R4P) !< test_passed(1) = real_==3.4e9_R4P !< print '(L1)', all(test_passed) !<``` !=> T <<< class(string), intent(in) :: self !< The string. real(R4P), intent(in) :: kind !< Mold parameter for kind detection. real(R4P) :: to_number !< The number into the string. if (allocated(self%raw)) then if (self%is_real()) read(self%raw, *) to_number endif endfunction to_real_R4P