6 kyu

A floating-point system

65 of 230g964

Description:

A floating-point number can be represented as mantissa * radix ^ exponent (^ is raising radix to power exponent). In this kata we will be given a positive floating-point number aNumber and we want to decompose it into a positive integer mantissa composed of a given number of digits (called digitsNumber) and of an exponent.

Example:

aNumber = 0.06

If the number of digits asked for the mantissa is digitsNumber = 10 one can write

aNumber : 6000000000 * 10 ^ -11

the exponent in this example est -11.

Task

The function mantExp(aNumber, digitsNumber) will return aNumber in the form of a string: "mantissaPexponent" (concatenation of "mantissa", "P", "exponent"). So:

Examples:

mantExp(0.06, 10) returns "6000000000P-11".
mantExp(72.0, 12)   returns "720000000000P-10"
mantExp(1.0, 5) returns "10000P-4"
mantExp(123456.0, 4) returns "1234P2"

Notes:

  • In some languages aNumber could be given in the form of a string:
    mantExp("0.06", 10) returns "6000000000P-11".
    
  • 1 <= digitsNumber <= 15
  • 0 < aNumber < 5.0 ^ 128
  • Please ask before translating
Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedDec 16, 2019
PublishedDec 16, 2019
Warriors Trained1213
Total Skips81
Total Code Submissions3038
Total Times Completed230
Java Completions65
Kotlin Completions18
Shell Completions3
Ruby Completions20
Python Completions123
Rust Completions17
Total Stars28
% of votes with a positive feedback rating80% of 69
Total "Very Satisfied" Votes49
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes8
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • g964 Avatar
  • SQSCWQ Avatar
Ad