My Math Forum  

Go Back   My Math Forum > Science Forums > Computer Science

Computer Science Computer Science Forum


Reply
 
LinkBack Thread Tools Display Modes
November 1st, 2018, 09:22 PM   #1
Banned Camp
 
Joined: Oct 2018
From: Mumbai

Posts: 18
Thanks: 0

Reverse of a floating or decimal point number

Reference :

https://www.programmingsimplified.co...reverse-number

Is it possible to write a computer program which will reverse a decimal or floating point number?

Example : 341.54

Output : 45.143

Do we have to just change the data type to float or double instead of int in the above C program reference or the programming logic has to be also modified?

Thanks & Regards,
Prashant S Akerkar

Last edited by akerkarprashant; November 1st, 2018 at 09:27 PM.
akerkarprashant is offline  
 
November 1st, 2018, 11:29 PM   #2
Senior Member
 
Joined: Feb 2016
From: Australia

Posts: 1,734
Thanks: 605

Math Focus: Yet to find out.
Yes you could easily store each digit of a number in a vector and then just flip it and put the digits back together.
Joppy is offline  
November 2nd, 2018, 12:41 AM   #3
Banned Camp
 
Joined: Oct 2018
From: Mumbai

Posts: 18
Thanks: 0

Thank you.

Can you please send me the computer program in C , C++ , Java , C# & Python programming languages ?

I will compile with the respective compilers and run the program in the respective SDK.

Once again , thank you.

Thanks & Regards,
Prashant S Akerkar

Last edited by akerkarprashant; November 2nd, 2018 at 12:43 AM. Reason: Content.
akerkarprashant is offline  
November 2nd, 2018, 04:44 AM   #4
Math Team
 
Joined: Dec 2013
From: Colombia

Posts: 7,502
Thanks: 2511

Math Focus: Mainly analysis and algebra
Quote:
Originally Posted by akerkarprashant View Post
I will compile with the respective compilers and run the program in the respective SDK.
That's big of you.

The art of programming is to pick the language to suit the application. There's no point in writing something so basic in so many languages unless you are doing it for practice.

Perl:
Code:
> perl -e 'print scalar(reverse shift), "\n";' 3.14
41.3

Last edited by v8archie; November 2nd, 2018 at 04:56 AM.
v8archie is offline  
November 2nd, 2018, 08:22 AM   #5
Banned Camp
 
Joined: Oct 2018
From: Mumbai

Posts: 18
Thanks: 0

Thanks.

https://perlmaven.com/reverse

As you mentioned in Perl code, the scalar function is called which could be the inbuilt function in the Perl math or string library.

Can you give me the source code of the scalar function?

This is required to know the algorithm or programming logic for giving us the reverse of a floating or decimal point number.

As you see,

https://www.programmingsimplified.co...reverse-number

There is a source code for reverse of a Integer data type.

Similarly, Can we have the source code of a reverse of a floating or decimal point number?


Thanks, once again.

Thanks & Regards,
Prashant S Akerkar

Last edited by akerkarprashant; November 2nd, 2018 at 08:33 AM. Reason: Content
akerkarprashant is offline  
November 2nd, 2018, 09:24 AM   #6
Global Moderator
 
Joined: Dec 2006

Posts: 19,878
Thanks: 1834

Reversing a floating point number isn't properly defined in the question. The example reverses a number given in decimal form, not floating point form.
skipjack is offline  
November 2nd, 2018, 11:06 AM   #7
Math Team
 
Joined: Dec 2013
From: Colombia

Posts: 7,502
Thanks: 2511

Math Focus: Mainly analysis and algebra
Quote:
Originally Posted by akerkarprashant View Post
Can you give me the source code of the scalar function?

This is required to know the algorithm or programming logic for giving us the reverse of a floating or decimal point number.
No, I can't. But neither is it necessary. One needs only a rudimentary understanding of Perl and it's variables.

The scalar function forces the reverse function to treat the input as a string rather than as an element of an array.
v8archie is offline  
Reply

  My Math Forum > Science Forums > Computer Science

Tags
algorithm, decimal, floating, number, point, reverse



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
exercise problem IEEE 754 floating point abdel Computer Science 4 June 14th, 2017 01:30 AM
floating point numbers with modulus(mod) abady-1 Number Theory 5 September 21st, 2013 03:08 PM
Floating Point Notation... Primalscientist Computer Science 9 June 2nd, 2011 07:29 AM
Precision Arithmetic: A New Floating-Point Arithmetic Chengpu Linear Algebra 0 May 23rd, 2010 05:55 PM
Floating Point Numbers - Single Precision Format (help!) RonnieStokie Algebra 3 December 12th, 2007 10:36 PM





Copyright © 2018 My Math Forum. All rights reserved.