String exponent number to integer and double conversion

Anyone who can help please,
I am receiving data back from an Agilent E4407B with the noise figure option in the following form:
+1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001,
for up to 401 pairs of frequencies and amplitude figures.  This is all coming back in one long string.
I want to read the pairs of figures into a 2 dimensional array, so that the first part of the array has the frequency in an double format, but NO exponent, and the second part of the array has the ENR value agan in a double format and also with NO exponent.
I have been using:
double ENR_Data[401][2];
Scan(Databuf,"%s>%401f[x]",&ENR_Data);
This reads the data into the array, but retains the exponent - please can someone show me the correct Scan formatting functions to use so that I keep just the number, and loose the scientific exponent format?
Many thanks for any help,
Allen Cherry

Allen:
It doesn't matter how you represent the doubles: the compiler represents them the same.
double a = 2000000000.00;
double b = 2e9;
As far as the compiler is concerned (and as far as you should be concerned), a==b.
In your last reply, your interpolated value of (say) 25000000000 = 2.5e10, which is greater than 2e9 and 3e9.  You said you may have the wrong number of zeros in the example, but please make sure you have the right number of zeros in your code.
Are you sure you are handling the array correctly?  Remember that the array subscripts are [row][column].  From your sample data, the frequency values are in column 0.  The first frequency value would be ENR_Data[0][0].  The second frequency value would be ENR_Data[1][0], followed by ENR_Data[2][0], etc.
Check the code I included below.  It's based on the numbers shown in your example.  It correctly determines if a number is greater than or less than a desired interpolated point.
P.S. What algorithm are you using to do you interpolation?  I don't even know why you are searching for a number greater than some known value: you should be interpolating between points read from the array.
#include <ansi_c.h>
#include <utility.h>
#include <formatio.h>
main()
 char Databuf[] = "+1.00000000E+008,+1.52799997E+001,+1.00000000E+009,+1.52200003E+001,"
     "+2.00000000E+009,+1.51099997E+001,+3.00000000E+009,+1.50799999E+001";
 double ENR_Data[401][2];
 double interpValue = 2.5E9;
 // same as
 // double interpValue = 2500000000.00;
 int i;
 Scan(Databuf,"%s>%401f[x]",&ENR_Data);
 for (i=0; i<4; i++)
  if (ENR_Data[i][0] > interpValue)
   printf("%f (%e) > %f (%e)\n",
    ENR_Data[i][0], ENR_Data[i][0],
    interpValue, interpValue);
  else
   printf("%f (%e) <= %f (%e)\n",
    ENR_Data[i][0], ENR_Data[i][0],
    interpValue, interpValue);
 printf("Press any key to continue...\n");
 GetKey();

Similar Messages

  • Integer and fractional part of the number

    Hello everybody,
    I want to divide the floating point number to 2 integer words, first will receive the interger part of number, and the second will receive the fractional part of the number.
    For example: I have number 751.98 in DBL, then I create two integer fields: first has value 751, second has value 98.
    I have tried simple conversion from DBL to I16, but it always rounded me to higher interger. I don't want to round it. And I just don't know how to transform the fractional part to integer. Are there any specialized functions for this? Maybe should I use log10 or similar?
    TIA,
    Jacek.

    The place to start with this problem is the IEEE-754 numerical
    representations:
    32 bit floating point is internally:
    highest order bit is the sign bit.
    the next 8 bits are the exponent bits
    the last 23 bits are the mantissa bits
    the mantissas and exponents are binary.
    the mantissa value in a 1.22 fixed point binary number, i.e. the most
    significant binary bit is equal to 1, the next most is equal to 1/2,
    the next most is equal to 1/4, etc., etc.
    The exponent part can go between 2^-127 and 2^128
    You should be able to cast your 32 bit float to a 32 bit unsigned
    integer, separate it into sign, mantissa and exponent parts, use the
    exponent to rotate left or right your mantissa decimal point by the
    exponent value and then separate the whole part from the fractional
    part and then put each into the I16's or U16's as you want.
    Douglas De Clue
    LabVIEW programmer
    [email protected]
    [email protected] (Michael Ross) wrote in message news:...
    > This problem needs some limits. Like: only return the decimal portion
    > out to 6 places.
    >
    > First run the number through Remainder and Quotient (divisor of 1).
    >
    > 751.98743674645641000000 gets remainder of
    >
    > 0.98743674645641021900
    >
    > "floor" is 751
    >
    > Take the remainder and send through Decimal to Fractional String (this
    > is where you set your number of decimal places [default is 6]).
    >
    > returns 0.987437
    >
    > Then use String Subset and set it to an offset of 2 (cleans off the
    > leading zero and decimal point) with the "length" input left at the
    > default of "rest" (of string).
    >
    > 987437 (in string form)
    >
    > Now use String to Decimal Number
    >
    > returns 987437 (as a decimal number)
    > ====================================
    > I think if you don't limit the number of places it is ugly. It is
    > ugly going from numbers to strings and then back. But all numbers is a
    > bad thing.
    >
    > The alogirithm for finding the answer mathematically is nasty.
    > Especially without a limit on decimal places. You have to figure out
    > the number of decimal places and multiply by the inverse of the last
    > decimal place. Sounds easy.
    > =============================
    > Try this: New number: 751.98652
    >
    > Truncate out the remainder (Remainder and Quotient (divisor of 1)):
    >
    > 751.98652 ---> 0.98652
    >
    > Mult by 10 ----> 9.8652
    >
    > Take the floor (9) and divide by 10 ----> 0.9
    >
    > subtract the new number from the old. Is the answer non-zero? Not,
    > then keep on
    >
    > 0.98652 - 0.9 = .08652 which not equal to 0
    >
    > If it is zero, the floor is the answer.
    >
    > Continue - Not:
    >
    > This time multiply by 100 ----> 98.652
    >
    > floor is 98, divide by 100 ----> 0.98
    >
    > Subtract 0.98 from 0.98652 = .00652 still non zero.
    >
    > Keep on. 1,000, 10,000...When you get to 100,000
    >
    > 0.98652 x 100,000 = 98652.00
    >
    > Get the floor
    >
    > divide the floor by 100,000 to get the original number (remainder is
    > now 0.000), compare to original remainder
    >
    > 0.98652 - 0.98652 = 0. Yay.
    >
    > Take the 98652 and go with it. The last place was the one hundred
    > thousandth.
    >
    > I can't take credit for the last, I had uglier stuff going on. I did
    > do the string thing.
    >
    > I swear this is just like some sorry homework problem.
    >
    > Mike

  • Incrementing a string number for date and time

    There are probably a lot of ways to do this, but I only want to use a bunch of if - else loops if I really need to.
    I have a date and time for input, let's say 2006-04-19 22:00. In Java, if I convert that to 3 integers (year, month, day), it will output 2006-4-19. I need to be able to increment in a loop for every day and month from one date to the next. If I keep it as a string, I won't be able to increment the value though, (at least I'm not sure how). I'm thinking that even if I converted it to an integer and back to a string, that the leading zero would be removed.
    I found a post here that said something about formatting the number with 2 numbers, by using:
    DecimalFormat format = new DecimalFormat("00");
    format.format(1, sb, new FieldPosition(0));
    Or is there a way to use the gregorianCalendar stuff that would output the date with all of the zeros in place, while incrementing and looping correctly?
    Thanks.

    I would get a Date object--you can use java.text.SimpleDateFormat if you're starting with a String--and use that to create a GregorianCalendar. Then you can just call Calendar's add method to add one to whichever field you want. Use the SimpleDateFormat to turn the date back into a String for display again.
    Calculating Java dates: Take the time to learn how to create and use dates
    Working in Java time: Learn the basics of calculating elapsed time in Java
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format

  • I am changing laptops and have tried to download and install Acobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    I am changing laptops and have tried to download and install Acrobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    If you had it on a laptop that crashed and you threw away, it is still considered as activated on that machine.  YOu should contact Adobe by chat or by phone and have them deactivate for you.
    Here is a link to a page with options to help make contact:
    http://www.adobe.com/support/download-install/supportinfo/
    If you are getting a message that indicates the serial number is not valid, you should look thru the following:
    Error "The serial number is not valid for this product" | Creative Suite
    http://helpx.adobe.com/creative-suite/kb/error-serial-number-valid-product.html

  • LV RT - String to double conversion

    Hello,
    I want to convert a string to a double on my Real Time device (PXI-8101. When I use the "scan value" or "Fract/Exp String To Number Function" VI the numbers after comma dissapear. This does not happen on the Host (PC). 
    So for example on the host vi, the string "2121,3" gives the number 2121,3. If I do the same thing on the Real Time, the string "2121,3" returns the number 2121. 
    How can I fix this?
    Thanks in advance,
    Regards,
    Dries
    Solved!
    Go to Solution.
    Attachments:
    String2Number.vi ‏7 KB

    Hello,
    Thanks for the reply, but scan from string also does not return the correct number on the RT device. The VI returns the number after comma as the remaining string. Any other suggestions?
    Best regards,
    Dries
    Attachments:
    String2Number.vi ‏8 KB

  • Diff between Integer and Number in Oracle

    Hi,
    What's the differet between integer and number in Oracle?

    u can say integer is a subset of number.
    integer provided by oracle for compatability with ANSI/ISO
    u can use number with scale=0 to represent integer values.

  • Can I use my email and phone number to start a new conversation from iMessage?

    Can I use my email and phone number to start a new conversation from iMessage?

    Can I use my email and phone number to start a new conversation from iMessage?

  • INTEGER and NUMBER in pl/sql

    Hi Experts,
    I have a procedure where I have to split the total contracted hours of a resource timesheet equally for 5 days.
    e.g if a resource has 36 hours, I should book 36/5 = 7.2 hours from Monday to Friday.
    I have used a INTEGER data type and the code in my procedure is like this:
      VN_EQUAL_HOURS      INTEGER;
    BEGIN
    VN_EQUAL_HOURS := (GS_HRS_AVAIL_WEEK/5);
    INSERT INTO XYZ (HOURS) VALUES (VN_EQUAL_HOURS);
    END;where GS_HRS_AVAIL_WEEK = 36
    Ideally I should get 7.2 in my table, but I am getting 7 !!
    Pls can you tell why it is removing the decimal part.
    Thanks

    Friends... got it !
    this time i declared the variable as
    VN_EQUAL_HOURS     NUMBER(5,2);
    and it is working fine now. Inserting 7.2 instead of 7
    Thanks.

  • Are Vector Integer and Vector String different types?

    Maybe I am missing something.
    Are Vector <String> and Vector <Integer> different types? Can I have to methods of the same name with arguments of these types? That would be the point of method overloading.
    Appearently not. The following code does not compile:
    import java.util.*;
    public class b {
            public static void doit(Vector <String> what) {
                    what.add(new String(""));
            public static void doit(Vector <Integer> what) {
                    what.add(new Integer(0));
    }$ javac -target 1.5 -source 1.5 b.java
    b.java:3: name clash: doit(java.util.Vector<java.lang.String>) and doit(java.util.Vector<java.lang.Integer>) have the same erasure
    public static void doit(Vector <String> what) {
    ^
    b.java:6: name clash: doit(java.util.Vector<java.lang.Integer>) and doit(java.util.Vector<java.lang.String>) have the same erasure
    public static void doit(Vector <Integer> what) {
    ^
    2 errors

    So it is not possible to have both methods in a class. Let us do instanceof instead.
    import java.util.*;
    public class b {
            public static void doit(Vector what) {
                            if (what instanceof Vector<String>) {
                                   what.add(new String(""));
                            else if (what instanceof Vector<Integer>) {
                                   what.add(new Integer(0));
    }javac -target 1.5 -source 1.5 b.java
    b.java:4: illegal generic type for instanceof
    if (what instanceof Vector<String>) {
    ^
    b.java:7: illegal generic type for instanceof
    else if (what instanceof Vector<Integer>) {

  • Random Double Number (Identifying lower and upper limits)

    Is it possible??

    I am going to explain the code:
    for (int i = 0; i < 5; i++){ // to print 5 balls
              Analog dots = new Analog(); // I have a class that creates circles. I create an instance
              dots.Graphics(g2D); // passed graphics 2D
               x = generator.nextDouble() * appletWidth; // I am generating a number between 0 and the width of the applet.
               y = generator.nextDouble() * appletHeight;// same applies for height
              if  ( x < ((appletWidth - 300)/2) || x > (300 + (appletWidth - 300)/2)) { // the diameter of the circle where I want to print the balls is 300
                    x = generator.nextDouble()* appletWidth;
              if (y < ((appletHeight - 300)/2) ||  y > (300 + (appletHeight - 300)/2)) {
                    y = generator.nextDouble()* appletHeight;
              dots.Dimensions(10); // I sent the dimension of the small balls (10x10)
              dots.setRandomCircles(x ,y); // passed the x and y generated by the random thingy
              dots.Coloured(Color.RED);//passed the colour. These are all setters
              dots.BlockFill();// invoked the method which is going to actually paint the balls
        }

  • How to use type cast change string to number(dbl)?can it work?

    how to use type cast change string to number(dbl)?can it work?

    Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
    2 simple examples:
    "1" cast as I8 = 49 or 31 hex.
    "1" converted to decimal = 1.
    "20" cast as I16 = 12848 or 3230 hex.
    "20" converted to decimal = 20.
    Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
    32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
    When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
    See tha attached LabView 6.1 example.
    Attachments:
    TypeCastAndConvert.vi ‏34 KB

  • Exponential String to Number

    Should be easy...but I'm getting hung up here:
    I am trying to convert strings in the form 1.40E00 to doubles in the form 1.400.  I am using the "Fract/Exp String To Number.vi", but it does not recognize the decimal values and returns only the integer values.  When I set precision past the decimal place, it returns 1.000 rather than 1.400.  Should be simple, but its kicking my behind.  Any quick fixes?

    Either your input to the function is wrong, or your method of displaying the output is wrong, the fucntions works fine unless you can show it not working properly.
    Please post an example of it not working, with inputs as a constant.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
    Attachments:
    Exponential String Conversion.vi ‏5 KB

  • Problems with convertNumber and Double values

    I've serious troubles using convertNumber with Double data in input fields.
    While output formatting works fine, the outputted string fails to be converted back - I get conversion errors.
    So the value that is written to the input field generates a conversion error being submitted! This is not good practice!
    I've found out the following: (I use german locale, so following examples containing ',' means decimal point)
    <f:convertNumber pattern="##0.00" />generates the right output, eg. for Double(20.50) - "20,50", but this value ("20,50") will not be parsed using the above pattern! Only values with non zero last minimum fractional digit (eg "20,51", "20,59", ... ) will be parsed!
    In addition, the above pattern doesn't parse numberstrings that don't contain all significant digits.
    For example an input of "20" will not be parsed to "20.00"!
    Maybe this is not the right forum for that problem, since i think this is a general java formatting problem (?).
    But as the problem arised by using the convertNumber tag and acting like this on numeric input fields is not very comfortable, I liked to post this here. Maybe someone can give me some advice?

    I also have found this problem, except that in my experience it is the decimal part that must be non-zero, not just the last digit of the decimal part. So with a pattern of "0.00" the string "1.50" (one and a half) will be accepted whereas the string "1.00" will not.
    My guess (just a guess) is that it is related to the documented behaviour of the DecimalFormat object when it parses a number. According to the documentation:
    The most economical subclass that can represent the number given by the string is chosen. Most integer values are returned as Long objects, no matter how they are written: "17" and "17.000" both parse to Long(17). Values that cannot fit into a Long are returned as Doubles. This includes values with a fractional part, infinite values, NaN, and the value -0.0. DecimalFormat does not decide whether to return a Double or a Long based on the presence of a decimal separator in the source string. Doing so would prevent integers that overflow the mantissa of a double, such as "10,000,000,000,000,000.00", from being parsed accurately. Currently, the only classes that parse returns are Long and Double, but callers should not rely on this. Callers may use the Number methods doubleValue, longValue, etc., to obtain the type they want.
    Which means that "1.50" will be returned as a Double while "1.00" will be returned as a Long. Perhaps there is then a class-cast exception whie trying to use this value?
    If this is indeed the problem, the solution is to use the getDouble() method of the parsed Number to create the Double to be returned, but this is for the implementer to do - not the user!

  • Expression Builder: convert string to number

    Hi all,
    I'm having trouble building a field validation rule for bank account numbers.
    The numbers have 12 positions, so I cannot use a string or text number.
    The validation rule to be implemented is that the last two digits are calculated based on the first 10 (modulo 97).
    However, when I use the Mid function to pick the first characters, I am unable to do any calculations on it. Apparently, the string to number conversion doesn't work (it should work when I read the manual, as it says that when using an operator between two data types, the second type is converted to the first (cf. example of 1234+abcd (should result in 1234 as to the manual))). So I tried '1*Mid(...)' or '0+Mid(...)'. Syntactically the expression builder accepts it and I can save it. BUT when I change the particular value on the screen, it gives me an SSO error (not the Field Validation error message I entered).
    Why isn't there simply a function ToNumber (like ToChar)????? How could I workaround this?
    Any input very welcome!
    Frederik

    Apparently, I was a bit confused when typing the first sentence, it should be:
    The numbers have 12 positions, so I cannot use an integer or number data type, but have to use String.

  • Problem Integer and Float

    Hi all,
    i am having a problem in comparing a integer with a number
    (float and double).
    can any one help me in showing how we can Differentiate a
    integer and float or double in flex.
    Thanks
    Maaz

    You can check what type a value is with the 'is' operator.
    if (someVar is Number) do something;
    else if (someVar is uint) do something else;
    You can compare them with standard comparison operators: ==,
    <, >
    You can convert a Number to an int or other type:
    var someInt:int = int(someNumber);
    This conversion will simply truncate the decimal portion of
    the Number. If you need rounding, you will need to use the Math
    round function.
    Vygo

Maybe you are looking for